Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for de-novo creation of all the OpenShift / NFS fixtures (in namespace wwp-int) #107

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e30a69e
first wp-blue integration draft
batKem Jul 22, 2019
255940c
second draft, starting to unfork
batKem Jul 24, 2019
c8f5e89
minishift checks and image stream setup
batKem Jul 26, 2019
796d943
deleted env vars from the runtime
cpittet Jul 24, 2019
3d724f7
added inventory file with 3 test sites in minishift
cpittet Jul 25, 2019
dd751d1
Creates sites directories in the NFS according to the inventory, nfs_…
cpittet Jul 26, 2019
3044313
nfs_path problem fixed
cpittet Jul 26, 2019
ead9217
deployment on prod images in parrallel POD SETUP NOT WORKING YET
batKem Jul 29, 2019
94910fd
added anyuid policy, deleted meta: end_play
cpittet Jul 29, 2019
8ed021b
mgmt prod pod and mysql architecture generation
batKem Jul 30, 2019
ce43534
added WP_ENV var in wp deployment and IF NOT EXISTS for db generation
batKem Jul 30, 2019
8b9db28
dynamic ip lookup
batKem Jul 30, 2019
70ad670
fixed service and route port forwardingé
batKem Jul 30, 2019
e5871d4
changed image tag on latest
batKem Jul 30, 2019
f223e28
reverted service and route ports
batKem Jul 30, 2019
fec35e2
reveted image to :prod and ports to :8080
batKem Jul 30, 2019
0018af6
revert back to port 80
batKem Aug 5, 2019
86cd7fd
revert back to wordpress stock image and fixed eyaml key path placement
batKem Aug 5, 2019
1de42c9
fixed dynamic ip lookup for minishift
batKem Aug 5, 2019
ab92fff
only mgmt in preparation for wp-int deployment test
batKem Aug 5, 2019
52239b8
functional wordpress+mgmt deployment
batKem Aug 9, 2019
1fb5fea
isolated and cleaned branch's features
batKem Aug 12, 2019
88fca67
backup volume mount
batKem Aug 14, 2019
b54dfb3
python dyn inventory+ mgmt test
batKem Aug 14, 2019
165ebdd
TODOs pour Mohamed
Aug 14, 2019
d030af5
fonctionnal instance inventory + restore task sketch
batKem Aug 15, 2019
9a72b5b
db restores and config generation
batKem Aug 16, 2019
ce97561
untar transforms
batKem Aug 19, 2019
3eff01e
fixed symlinks
batKem Aug 19, 2019
ad79726
temporary stage, started unforking, better inventories
batKem Aug 21, 2019
7d5f187
cleanup
batKem Aug 26, 2019
2a81da0
upgraded inventories to python 3
batKem Aug 26, 2019
082c857
better inventory
batKem Aug 27, 2019
83e8360
more unforking in wordpress-instances role
batKem Aug 27, 2019
ce2f0b7
more unforking in wordpress-instances role (for real this time, bad p…
batKem Aug 27, 2019
345ae02
more unforking, refactoring deployments
batKem Aug 27, 2019
e944789
added automated rollouts and modified doc
batKem Aug 27, 2019
75351e2
Remove `wp_dir_tar` and `wp_dir_tar_raw` (dead code)
Sep 25, 2019
6eb08cb
Fix clash on `wp_access_path` declaration
Sep 25, 2019
ec75e5c
Make `sanitize_tar_path` useful
Sep 25, 2019
56f9d32
[fix] Extract only the "real" .htaccess
Sep 25, 2019
a87f5e8
[fix] Use re.sub rather than the .replace() string method
Sep 25, 2019
4f529af
[fix] Confusion between “before” and “after” paths
Sep 25, 2019
1a83a65
Remove some dead code
Sep 25, 2019
4617344
[fix] Must parse tar path out of the archive name
Sep 25, 2019
c583700
[refactor] change wp_ to restore_ in relevant variables
Sep 25, 2019
01fc479
[refactor] Define and use restore_tar_full_path
Sep 25, 2019
63e98f9
Don't assume Python executable path
Sep 25, 2019
b16a336
[fix] Do string concatenation in Jinja, not Python
Sep 25, 2019
16841c4
[fix] When multiple mgmt pods are present, use only the first
Sep 25, 2019
2aa0cd6
[fix] Another Mac fix
Sep 25, 2019
0a5c855
[unfork] We want to do facts regardless of where
Sep 25, 2019
26e2ba4
[feature] ssh key material for wp-blue / wwp-int
Feb 4, 2020
f3dbf8e
[WIP] Unfork wwp-int-mgmt.yml out of mgmt.yml; to be continued
Feb 4, 2020
54c0c39
enabled ssh connection for tasks on mgmt pod (needs manual port forwa…
batKem Feb 5, 2020
496851a
enabled --connector option on wpsible command to chose connection typ…
batKem Feb 5, 2020
4ce5d66
Factorized plugin reactivation commands for performance
batKem Feb 6, 2020
43e35e3
Added ssh pipelining to ansible configuration
batKem Feb 7, 2020
62b8d2f
[WIP] unforking mgmt deployment, still forked for deployment rollouts…
batKem Feb 7, 2020
01fe5b5
Fixed Mohamed's ssh key in ansible/vars/ssh-keys.yml
batKem Feb 7, 2020
6a9345c
[WIP] (Unforking) added namespace variable for conditional mgmt deplo…
batKem Feb 7, 2020
f451510
Finished unforking mgmt deployment tasks and variables
batKem Feb 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Restore-Connector-doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Temporary documentation about how to utilize ssh or oc connector for the restore-from-prod task set
Targeted tasks by the connector:
wp-ops/ansible/inventory/wp-int/wordpress-instances
wp-ops/ansible/roles/wordpress-instance/tasks/restore-from-prod.yml

Prerequisits:
logged in oc on project "wp-int"
running mgmt pod on project "wp-int"
running desired httpd pod for the desired restores on project "wp-int"
export mgmt ssh port to desired local port:
`oc port-forward -n wp-int <mgmt_pod_name> <local_port>:22`
change `port` variable in wp-ops/ansible/inventory/wp-int/wordpress-instances to be equal to `<local_port>` (default local port is 2222)

Usage:
```
cd wp-ops/ansible
./wpsible -l <group> --connector <connector>
```
where <connector> is either `ssh` or `oc`
`--connector` option is *not* optional for this inventory and is *ignored* for other inventories
56 changes: 56 additions & 0 deletions WWP-INT-DOC.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Feature: wwp-int

This feature allows restoring from backups on a sandbox openshift cluster

PREREQUISITES:
- python 3 with pyyaml library(for inventory and filters)
- a working oc client
- a working ansible installation
- current-context must be "wwp-int/pub-os-exopge-epfl-ch:443/"*:
batKem marked this conversation as resolved.
Show resolved Hide resolved
use "oc config current-context" to check the current context
use "oc config use-context <context_name>" to choose context
batKem marked this conversation as resolved.
Show resolved Hide resolved
use "oc login" to login to the desired context

USAGE:

- if wwp-int cluster is empty:
batKem marked this conversation as resolved.
Show resolved Hide resolved
"./wpsible" will only deploy mgmt with:
- mount on production backup nas in /backups
- mount on wwp-int's persistent volume provision system in /srv

- if mgmt is deployed AND mgmt pod is running (if not, deploy mgmt manually on the OKD console or use "oc rollout latest dc/mgmt"):
- if respective wordpress servers are NOT deployed:
"./wpsible" will deploy all httpd deployments only (permission for creating file structure will be denied)
- if respective wordpress servers ARE deployed:
"./wpsible" will deploy all httpd deployments AND wordpress instances gathered from /backup mount

- to limit httpd server deployments :
"./wpsible -l '<server_name1>, <server_name2>..' " where <server_name#> is of the form httpd-[environment]

- to limit wordpress instances :

* "./wpsible -l '<instance_name1>, <instance_name2> ...' " where <instance_name#> is the name of the backup
folder for the specific instance (fetched from /backups)
example:
./wpsible -l _srv_www_www.epfl.ch_htdocs
./wpsible -l '_srv_www_www.epfl.ch_htdocs, _srv_www_www.epfl.ch_htdocs_about'


* "./wpsible -l '<environment1>, ...' " where <environment1> is the name of the group of wordpress instances
example:
./wpsible -l httpd-www
./wpsible -l 'httpd-www, httpd-inside'

* edit the python dynamic inventory ansible/inventory/wp-int/wordpress-instances:
- call generate_inventory(sorted= True, limit=0, max_depth=-1) (bottom of the file)
"sorted" will sort instances by file depth,
"limit" will truncate instance lists in each group until the specified number. A value of 0 will not limit instances number
"max_depth" will filter instances by file depth. A depth strictly smaller than 0 will not filter instances, 0 yields root
wordpress directories only, ect.

- to get an inventory listing for a given dynamic inventory:
structured:
ansible-inventory -i <inventory_script> --graph
full variable listing:
ansible-inventory -i <inventory_script> --list

2 changes: 2 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ssh_connection]
pipelining = true
18 changes: 18 additions & 0 deletions ansible/eyaml/epfl_wp_blue.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC2TCCAcGgAwIBAgIBATANBgkqhkiG9w0BAQsFADAAMCAXDTE5MDcxNzExMjgz
MVoYDzIwNjkwNzA0MTEyODMxWjAAMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEA3zdra3NGYwb/mrroMSuJsO0uUK9us6sWErBiBb4OT4CC1K0G57Fgq5Kh
lSsZ+0OLV/CtIJYNYnl0dQzdHJgS/h2YC2kfTGHPRFULE5mysIvXZrEQXJvEaJpS
pxFu3L7gZlacGHTPNlXmEmtfVFetpfRZKo0btDf76XdSEZ1d9ItOMXNYH+MUM3qk
dHzgfDnA8eyQI7naGAdBtCrouMDWWfQKuKl2swZeMdh1FnB4z0r1cQhnanWvajwg
p35iw72Ltkz18bXH6Fh0ODo985Mgzyar71bbl3HdidGpLB2VhywQQxEO6Sn1Ikte
IP2PZ+lIQmbLZ+doqfo+8d2Ci5N6hwIDAQABo1wwWjAPBgNVHRMBAf8EBTADAQH/
MB0GA1UdDgQWBBQQUtgvd0IhtNfSrP7UDHFnpely3DAoBgNVHSMEITAfgBQQUtgv
d0IhtNfSrP7UDHFnpely3KEEpAIwAIIBATANBgkqhkiG9w0BAQsFAAOCAQEApyiZ
0DkuWPlDgA+clkxPMyKkVoi9+BMespjslvES/rFbpPVZ/6kuYAxG9/4SW5V3xsx3
hwHWDts/tu46IiSw3p2tXX0QMnSJmoFqg8KNZOdc3cVZdo8apZjq8A27qMeOlWwC
YmMcf94Of8ipCg2NthdxDDmbwPTkz2JiGz8gAI9LTUrOQjMrvEw3DHRKYIlpnm9u
eo+pzPyeUOxHjBtQdmbcrJ1Yw5EwVSFtkgLdxR18C/eIBD/qT3q9WkKRl+ufwjap
Lwi1ePHgj9Edd7t0PfUJjHA2Y6W5qDyF89FUL/H3sZmTYJX0rW8vjrXvXq4bDJ9F
6Ivpnv8vwBjDM62mMA==
-----END CERTIFICATE-----
36 changes: 36 additions & 0 deletions ansible/inventory/wp-int/group_vars/openshift-namespaces-blue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- mode: yaml; -*-
#
# Variables that only apply to members of group "openshift-namespaces-prod"
ansible_user: www-data
ansible_connection: local
openshift_namespace: wwp-int


eyaml_keys:
priv: "/keybase/team/epfl_wwp_blue/private_key.pkcs7.pem"
pub: "{{ playbook_dir }}/../eyaml/epfl_wp_blue.pem"

# To edit the encrypted secrets below, you need eyaml installed.
# Familiarize yourself with
# https://puppet.com/blog/encrypt-your-data-using-hiera-eyaml first.
# The edit command goes like this,
#
# eyaml edit -d \
# --pkcs7-public-key ansible/eyaml/epfl_wp_blue.pem \
# ansible/inventory/wp-int/group_vars/openshift-namespaces-blue
#
# 💡 This *will not* decrypt anything for you because chances are, you
# don't need to decrypt secrets (YA RLY). For those cases where you
# do, wielding the private key from Keybase is left as an exercise to
# the reader.

mgmt_sshd_keys:
ssh_host_ecdsa_key:
pub: ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKmlErFrPfGGaMaC/wMjgkOoLO25HDGbcjIw2pbZwS3yTEU4EUVQBMDkw+1EyKqD/81aj+8wjwkC+k7qIwngVPM= root@mgmt-351-build
priv: ENC[PKCS7,MIICXAYJKoZIhvcNAQcDoIICTTCCAkkCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAcYLjW33kpI3CS/XXpclVr2zJM6ylOtalADBXBOBz7JGWa8o8OBpOjKyREJd5kL4F0C3IqVnRRWdMDqbAQyOjBgX0+kXNz/Eq4S6JqgonhqySynwkUcgbQtwQdUF//LBvmTN6q8krni5J6FgQuKY48DcqBbHI17uZZA/HpkY4Yz0KRi1yqBjwJMfa4otA6pcYMEWMVatQYkr3owucj+3+W3re60gsZol5u7+uEEaQev7JUum5yXFmBgFlOgGOR29gjxliC3pKx7FM1zRggtJtzwWRj8SV/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9kjQDNVw1iZGGi2F09I/vRkMdYXf4UiHeNjAIf0lKH1Y9bo6ZKwTokp+XpWfcT7jgjvPokvSXPirIPzEkwVTsSKjBYHwd1OEid7gUzMgQrZ0INTiIDtFyM6L6UMk9UdtLjPqaGo5Umf3JCKrCZhI/t26WvK6qv8LxfAtvgciRLsc3AuBkuSLiXSpPNPYmS24hj6Vg11SFqONnHYdLtEXChvv+uHe13mbkrhplozNnoytE383KPOOcdqrGs4MYPpqmAvq4h1G7enP0rRnyOy1I2/ubXYN7+G6krzyv2/mbGtVgfZ1VzU73wsXmkaOA+5NmOew3eS5yqNOJcQoDKbL9kaHyQBHWWoXdNuc5+HonyGfug0HTW2VTV/9dgvEoovv91/IKBBWqilWiG1tMUykzSdoTK16uPl0SkGIek]
5 changes: 5 additions & 0 deletions ansible/inventory/wp-int/openshift-namespaces-blue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[all-openshift-namespaces:children]
openshift-namespaces-blue

[openshift-namespaces-blue]
wp-blue nfs_path=nfsshare
113 changes: 113 additions & 0 deletions ansible/inventory/wp-int/wordpress-deployments
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env python3

import subprocess
import yaml
from sys import stdout
from collections import OrderedDict

pod_name = subprocess.check_output('oc get pods -o name |grep mgmt | cut -d "/" -f2', shell=True).decode('utf-8').replace('\n','')

def parse_backup_directory(nb_sites):
if pod_name == "":
return ""
command = "oc exec %(pod_name)s -- ls /backups " %{"pod_name":pod_name}
ls = subprocess.check_output(command, shell=True).decode('utf-8')
if "Error" in ls:
return ""
return list(filter(lambda x: len(x) > 0, ls.split('\n') ))

inventory = {
"all-wordpress-deployments":{
"children":
["wordpress_deployments_test_blue"]
},
"wordpress_deployments_test_blue":{
"vars":{
"openshift_namespace":"wwp-int"
}
},
"_meta":{
"hostvars":{}
}
}

def group_by_env(hostvars):
groups={}
group_hosts={}
for k in hostvars:
env = hostvars[k]["wp_env"]
if not env in groups:
groups[env]= {}
if not env in group_hosts:
group_hosts[env]={}
group_hosts[env]["hosts"]= []
groups[env][k]=hostvars[k]
group_hosts[env]["hosts"].append(k)
return {"group_hosts":group_hosts, "groups":hostvars}


def populate_vars():
ls = parse_backup_directory(20)
ls_hosts= []
vs = {}
for name in ls:
vars = parse_vars(name)
name = vars["wp_hostname"].split('.')[0]+"-"+vars["wp_path"]
ls_hosts.append(name)
vs[name] = vars
return vs

def get_latest_full_backup(bkp_string):
#TODO performance bottleneck in the repeated oc command
command = "oc exec %(pod_name)s -- ls /backups/%(bkp)s " %{"pod_name":pod_name, "bkp": bkp_string}
ls = subprocess.check_output(command, shell=True).decode('utf-8')
bkp_list = list(filter(lambda x: len(x) and "full" in x > 0, ls.split('\n') ))
bkp_list.sort()
reversed_bkp_list = bkp_list[::-1]
#TODO check edge cases: we suppose that each archive has a same-named sql backup
#and that there exist backups in the first place
if len(reversed_bkp_list) > 1:
return {"restore_archive_name": reversed_bkp_list[0], "restore_sql_name": reversed_bkp_list[1]}
else:
return {"restore_archive_name": "none", "restore_sql_name": "none"}


def parse_vars(bkp_string):
if '_' in bkp_string:
path = bkp_string.split('_')[2:]
wp_env = path[0] #TODO make wordpress environnements dynamic as well > use path[0]
wp_hostname= path[1]
wp_path = bkp_string.split("htdocs")[1].replace('_','')
# wp_archives= get_latest_full_backup(bkp_string)
return {
"name":wp_env,
"wp_env":wp_env,
"wp_hostname":wp_hostname,
"wp_path":wp_path,
# "restore_archive_name":wp_archives["restore_archive_name"],
# "restore_sql_name": wp_archives["restore_sql_name"],
# "restore_backup_folder": bkp_string
}
else: return {"name":"",
"wp_env":"",
"wp_hostname":"",
"wp_path":"",}

gen = populate_vars()
#inventory["_meta"]["hostvars"] = gen
output = group_by_env(gen)
inventory["wordpress_deployments_test_blue"]["children"] = []
for k in output["group_hosts"]:
if len(k)>0:
inventory["g-httpd-"+k] = ["httpd-"+k]
inventory["wordpress_deployments_test_blue"]["children"].append("g-httpd-"+k)
inventory["_meta"]["hostvars"]["httpd-"+k]= {"name":"httpd-"+k, "env":k}




print ( yaml.dump(inventory) )
#print ( inventory)
#print(yaml.dump(group_by_env(gen)))


Loading