From b01ae836f5f686c638fbcc20f9a4fea409b9a60b Mon Sep 17 00:00:00 2001 From: "Gordon, Alexander" Date: Fri, 27 Aug 2021 13:15:35 +0000 Subject: [PATCH] DEV-167: feat: creating maria database for connect-wordpres provisioning --- create-database-cluster.yml | 17 +- group_vars/all/vault.yml | 171 +++++++++--------- group_vars/connect/plain.yml | 2 +- group_vars/connect_wordpress/plain.yml | 5 + group_vars/maria/plain.yml | 20 +- group_vars/stage_dev/plain.yml | 2 +- .../connect-wordpress-maria/defaults/main.yml | 18 ++ .../connect-wordpress-maria/handlers/main.yml | 1 + roles/connect-wordpress-maria/meta/main.yml | 1 + roles/connect-wordpress-maria/tasks/main.yml | 32 ++++ roles/connect-wordpress-maria/vars/main.yml | 1 + roles/maria/defaults/main.yml | 1 - roles/maria/tasks/_create-database.yml | 50 +++++ 13 files changed, 216 insertions(+), 105 deletions(-) create mode 100644 group_vars/connect_wordpress/plain.yml create mode 100644 roles/connect-wordpress-maria/defaults/main.yml create mode 100644 roles/connect-wordpress-maria/handlers/main.yml create mode 100644 roles/connect-wordpress-maria/meta/main.yml create mode 100644 roles/connect-wordpress-maria/tasks/main.yml create mode 100644 roles/connect-wordpress-maria/vars/main.yml create mode 100644 roles/maria/tasks/_create-database.yml diff --git a/create-database-cluster.yml b/create-database-cluster.yml index cbd53a0..06f6ffc 100644 --- a/create-database-cluster.yml +++ b/create-database-cluster.yml @@ -33,13 +33,25 @@ msg: "The ansible version has to be at least ({{ ansible_version.full }})" tasks: - - name: Add hosts + - name: Add postgres-servers to hosts add_host: name: "{{ stage }}-postgres-01" groups: - "stage_{{ stage }}" - "{{ cluster_service }}" changed_when: False + when: + - cluster_service in ['connect', 'webdav'] + + - name: Add maria-servers to hosts + add_host: + name: "{{ stage }}-maria-01" + groups: + - "stage_{{ stage }}" + - "{{ cluster_service }}" + changed_when: False + when: + - cluster_service in ['connect_wordpress'] ############################################################# # Setup databases for created inventory @@ -86,6 +98,9 @@ - role: connect-postgres when: "'connect' in group_names" + - role: connect-wordpress-maria + when: "'connect_wordpress' in group_names" + ############################################################# # Sending smardigo management message to process ############################################################# diff --git a/group_vars/all/vault.yml b/group_vars/all/vault.yml index faf1262..22e4347 100644 --- a/group_vars/all/vault.yml +++ b/group_vars/all/vault.yml @@ -1,85 +1,88 @@ $ANSIBLE_VAULT;1.1;AES256 -63376530643934386637626662623631623061333563363962653837326362373064633163653434 -3932613032336365623637393233383964643462643164330a336534316564343535633534623432 -38323037333363363331353765303866656435393138383164346234343062643031366539343039 -3138383136373332650a386162623764306433626264363464616532636464393561643638656263 -38303432303330623763386138663438353236393135373933623266643965396634633932323963 -39343537306563646163396466303935346263363562303038393430326233393931383838646435 -63306436376130353830613131343734613537653037353631353934346633623534326261616334 -30653837356363633530306233396536373038333563376565353962626631333262356233636361 -63616538633530626264343036373062336165636531303133373363393836343331626365646336 -37303565643662343339343737323834353235366366303630643565636362326336326132383363 -66653337633837333937383664653931363165363438656634356233656637656233356639343764 -36613833323537656662616338343637653834653639376662393362393530663964366438326362 -35393136393638333165356336643536326365393766643638333437663833323239353063303435 -34363037346437643037623066666133386531366636363763303235666634373361313434656461 -66396130613035323464356461306130383138656437613832353930636231373562313534356233 -62616439393230333363646139373061316432663435653031303533306163626164633964393461 -63643064643361316236346634376634313132656633613839336435336136316638333461303537 -62613265386562383735623362626137303532386337333836376336323339343630613037396337 -36646539333462626538356531333834353132636537623531366132306161326338333033393266 -64323534353339656163626435643565353638333661656434646138616230303233386463393437 -36333536633832656430353937616461376631396236383738666364666135386533323263623032 -33653636363966333334316161656465366365316664323437626235646636373630666266383739 -30636132353461346461366239663466393766353063373130303761376230316534393462393838 -65383835333632613839343734656532346363393066373237616162623865633036383535633565 -39353339356232613366323166636465356461326531313638653438366362356333373764396561 -34376432393633376431376465643963383934386361616462613132663564366530306635313532 -36653061343037393237376366373435323232333831626566366264633633663661386465353331 -33313838356233366531306364353061383735383836393139343233313632373938643834316239 -32326235616362653032643237333464306261353433653565346532366564623166636361306237 -36636262653862396430323739616163623034626136626562643663666337663134643564653339 -38343333643237313064616666336137663562616164633166376630616564623866656366633633 -39316663306131376434303034646133626661396366343763373337613633363732643364323238 -37653935633564643336646163346136336133393861373535396437323737363837326132336433 -34343137343234373631313535623439326334626466323866373838623465366531396137336665 -36623334376434643236653539383961626664363732656137306163616366383734306564386335 -61323864616339616463666430383931633233393063633362356565653063356537626630323639 -63323132333163323664646337303834386134353564376433363433383137366333393363623565 -62356230333831666665653061393332323539656531336264643866383063366565653966323939 -61313133623630376633346464643435326665396139666261333531383362333035346439323134 -30653666353431313461656235333035326431623261343565326361313835393935666436643738 -61316639633733323865363232373963366461393533383262623462303438393364653764303039 -32326239616262306430326535623037356634333265353566316364316137653736613331333564 -35353133333837626531343330663366653634353131383966303636613935356661643532616136 -39653139383064343937643939656438353763643466373239363064633036356461663533373835 -31323061663532626338373064313637663461306630633336343434303738396566393638346438 -37373362363233303133623130353637333737663762636466616233643335626165623664333539 -31643639386261656136663036643732396465333036376163376162393063303063396530396238 -37366562366361393932323962336436613964646662396466383730393035663862353437333136 -33333161666632613934366163363737333636343263373434376362353035653465393037636139 -64633931333164393233643163623735353636666337646239363463303164383638326264666566 -66656463646630313534356266616232383732336361393437333766303064616636366366336362 -37353939386335636637316139656337646561353936643839323134326531313763336238326362 -37343363646333303434316366383634386535616132663661363930393733333539396164353636 -36333832376331643739373936666661363364356230613438303137383766353839326436363765 -32623466313066306261666237396365656437613331613337613862336237663630323033323039 -30646563363337386138643537396333356130646163313134633362346635646333353836383839 -33313665346564376236663938343464656636363362666362363564613964323966316261393663 -64393161303861316433353865373962646665623831323463383838633731323536326631666164 -61323666323435326132316330313165623666393835346634323264393632353765313835353138 -38666362376661343366653133656362663633633261646633396239666635313866626332316161 -62303236366264303735646136653130613361353830333966346264623430633166386337353333 -31656232316135616538323966356138313531343963333732373363356561383838623065313831 -32316534303763383735643833363635363765346432643437323237376639373131363866313634 -65333434333664313163613561623734383632383536386264343639386633646131393037306634 -38333935396639383339383564336139303838653636366338623162396162623739666663633631 -64326265373334323365646330353439643961616339363436643236366639393530346330633966 -37393166623865643031366637666430326537383763623561666233353337653335656366333335 -66363561633730663361313236633033303239333130346464373735316131653966663864633836 -30356532303933306431353632646330656338383765613031656639666365613763663538326262 -63393834343433633732666630376530613163393166316135373638393236343734663436326435 -37663461333865303865366533366663623432383035643938653061343033373264326439393231 -65666266666436353762636465393561666437636132326633383264613332333730333632626331 -62623763366466626230623931646539303338343637353761326662643765376437656631333630 -30636139356261353365386338643261303134313430633666393331636238323639626334383032 -36326666383737346164666630643739623238323761653565306636633262646462666564663336 -38346635343836636361646564633263396663343861626535306235376364646633633662323835 -63653162336637646565373133656431393531636132346231396366613561343734353231386236 -64646639393532323231643930343438663762383963636566306434323664336231313438646163 -32633932323639393839343865396633636365396132336665633965363630306264303537373838 -35373439383334303963666230643463653839613766363737336339646662313334306432306338 -63386162303133323739633531626133386664326437626439353533303834636336363239316432 -30633961653463366131636636376431663164313838653761623334396136343935326566363364 -37333536356365393764363232336661313666393565363865386432353936663439323965363063 -66366537323562653861 +35636539303666386361386536343034303934663231616338626437393633316136636239653133 +3333353765333766663734336661383334613233633033300a313765326664623362663264306365 +62326237613434353961323735386536613466343264396435333939313863666165353263366461 +3035626333313632340a373263376666633836363866346337326566326532613536316366663065 +34306236353565633136623563656635383636376439613635633238653531303134626462653530 +38616563346362323634396531313733323639333136373730613839303530396634376439343761 +36383632646633373963313865386232363665653834333662373163393933656537643062306635 +63363731623634346561333137393036326630376232383638353338363436633232343237326336 +36343336326662623936396630666434383034303534616464623361666337396633663331303838 +38393261343866613130363062306530633531306262303761353763623330313838316564333530 +35326361653035656234303132653761366139386261376635623461386634303530633039653063 +65626433313935646632376430396432316133333366313638396461643735393033656336643539 +34383236626332326665356635316530306633646430656339393339393563626539306331303865 +35303861343265383066373166306231376336363161343936633837643766333466653764336331 +63393264323061303834353633333634373163396563356638623534343838626566663662396338 +33303561353436336436316530323739313630613230363934323936396139363866396536353036 +35353635626666326161376339323230323264613632643138343238396431306335666135376130 +30613465313337383533363465393836336662666230323132343036346633373338636565643038 +37666466303265323562346663346338343763653235373336343166656335376639356238306634 +34313835396636306632633636636564306164333533323161366537396461666363373466666137 +62343134353339343232613262336166343964663130333666333739383333353062623161643432 +66363130636539346466343434343038373061383635323764383232376334653964346163616533 +32366434366561333434366535653064666464326435306434343330383665303165373935626137 +38383063633837333938643664643766636363613036613366366234316661333235613436613833 +66663161396230663334336530643532316161653362663864646437376539633263346362353266 +34333631666163653463386437346336636633333534326139356533666336623832643332316132 +63343837373333336465666538613863313763313730303465626632643338666163646264363532 +38373064313133356537633739363762306266353130363266383062376237383733313964353061 +37393866343262393330356536386134316565643333366462383636313932623962643939396631 +35353761313965613861316232653663323038663137383066336261316365366330343631316131 +62353433393830333934346336646639333337666665643038373135646564386532363534333536 +66396234313038396230343238663865396563376666643134646633656263663430336430623861 +38613933366662383261643761663630623034616362303338646531616332333265333638663062 +33383936373432623064626232316630616633613762613231376433386536396432343633373938 +64656439626232363466376266633165326564633964303233333537636165306262323332663164 +32343138653630666436316333373966643164313336613465313039643034636364346266653764 +65613461303566356663623339373461386166626538323039323138633733643435353735323734 +34626234383938666433393463363634386136613062613632653130343333343039343263363939 +30633034326561303162373966326163393764616433643635313438323966653761313062383139 +38376164326335626632373535383034663264353439636534316636313038396630656538306162 +30353336306331633038336432393637323961343939306330613239393662373736353430663731 +32343935656235616261363439386564636634383934663266383563396239663431396665353532 +37353166323138616432346136633432313064636335616361333235653635346533313333656663 +62303664336161643165366538623361313838346136313635393536646532353237386337303335 +30343435353330333831633763363066626336306538666637613839366662353034666565616635 +65643861616530353966373737326336323336303134306166343733303363326565353931346534 +32353466623262633932353939383039666266653931383737326237616265383866333132333264 +38396666343066373664353765376639313937336638393334616665393864616564636464363632 +30383935653033636631363034643262353239623733626166616266666338393065366336653939 +37663431366564373762623638653031643232663639333332393764313062643665353530353934 +35636566663539383836363164343330383765363336373133363533363936653137626337333432 +30346631343665333134613363636636373839313335353730326361323263633234326465383231 +30346134366637346664333134366436366430616466646139633364343463333930343933346534 +32333664373037656361656238323836333833343931383334656333316165666466646339343964 +62616463353763653831623966663065373030336433376434306535393331383935353830633264 +31376633316439656665376265646266646265393835646536636631646334313134333236643333 +65383235653734366530336239383336326137356134346466373565663833636234366437643430 +31336261356263336663313639386639663034636430656238623730363263643432383037666162 +39303939323537306361636235623833343038363863303338376665366464336463393836666566 +36396436356661306335396239303331313665313462306566656435663162356661336234383933 +36613531303433343532333734353962623463396431623364333434343433616537353264353363 +39333334633134643430313737643730353639626566353566363337353038336330653839646639 +33663736626161646264363066343262343836363831313134353035303035393332653130623731 +30623531376435653564393035346534313633623632643764336161623136653861626137303563 +36323861333434653530663632363533323132643634373235303135323766626462383538393030 +36383134303932373161326262393733386261363464663239383335383033396530313963333762 +37666163626534633263386364356238303132333365306137306465366139303732613439363033 +32376635363836393338363166386161333264633665326163303633373432363330353635623333 +32623764363433343864396139623561663738376262313165396233663235663637623461333737 +35613334653434363234623462653037613330306235653538663462633564613965613363663630 +35336634656435343833303731393236633437613933323733653237356333663434643262313934 +38306434316538306235346335363765323865393332623239333631313730383037343934383839 +64323762613365336164643163663161353933353634346361386436643437663165613035323565 +33626534373162626633323964313736366431346335333562336463373566633662623563333932 +31303132356563366139363564663463323733633832343563323235356135376635633964386134 +61306439303165653138366436636438653439353235666335366134636636323062346161633763 +64656536303430346135303430386363663165646232313235303037366131646130313934376665 +33356539633338613937373431633735663139616633633562613637613734633935336135633536 +37613962323539363135383433626634376666306535623061333136363437363066336162333632 +38323965303637663532343237373935316538616639383532626261623632613237626561366435 +66633330653634646262646335323032333336326433613665653265373032313335323736393837 +35303139356432366561356532626663666539643738663164373761613838376332646235363032 +36646238373030626539653562383333613938336530326361613266373131626133626330623530 +36636538633566303331316438643864363737336532623038333235376165373631376662313933 +33646431366164326137323730633366386662386666646235663234383261643264333136346165 +35363136613031623362626561313266373438666264626531316135653635306430333634613162 +353261323932643731396437353134363766 diff --git a/group_vars/connect/plain.yml b/group_vars/connect/plain.yml index ff6d8cf..ada8bf8 100644 --- a/group_vars/connect/plain.yml +++ b/group_vars/connect/plain.yml @@ -46,7 +46,7 @@ current_realm_clients: [ connect_postgres_host: "{{ shared_service_pg_master_hostname }}" connect_postgres_database_name: "{{ stage }}_{{ tenant_id }}_{{ cluster_name }}_{{ cluster_service }}" -connect_postgres_admin_username: "{{ connect_postgres_database_name }}" +connect_postgres_admin_username: "root" connect_postgres_admin_password: "connect-postgres-admin" connect_elastic_host: "dev-elastic-stack-01-elastic" diff --git a/group_vars/connect_wordpress/plain.yml b/group_vars/connect_wordpress/plain.yml new file mode 100644 index 0000000..f3c0e64 --- /dev/null +++ b/group_vars/connect_wordpress/plain.yml @@ -0,0 +1,5 @@ +--- + +connect_wordpress_maria_database_name: "{{ stage }}_{{ tenant_id }}_{{ cluster_name }}_{{ cluster_service }}" +connect_wordpress_maria_username: "{{ connect_wordpress_maria_database_name }}" +connect_wordpress_maria_password: "connect-wordpress-maria-admin" diff --git a/group_vars/maria/plain.yml b/group_vars/maria/plain.yml index f697ab5..0c338b4 100644 --- a/group_vars/maria/plain.yml +++ b/group_vars/maria/plain.yml @@ -2,23 +2,9 @@ hetzner_server_type: cpx11 hetzner_server_labels: "stage={{ stage }} service=maria" +mysql_databases: [] +mysql_users: [] + -mysql_databases: [ - { - name: "demo01", - collation: "utf8_general_ci", - encoding: "utf8", - } -] -mysql_users: [ - { - name: "demo01", - host: "%", - password: "demo01", - priv: "demo01.*:ALL", - } -] -mysql_root_username: "root" -mysql_root_password: "maria-admin" diff --git a/group_vars/stage_dev/plain.yml b/group_vars/stage_dev/plain.yml index f002da0..5daa447 100644 --- a/group_vars/stage_dev/plain.yml +++ b/group_vars/stage_dev/plain.yml @@ -15,7 +15,7 @@ shared_service_elastic_03: "10.0.0.4" shared_service_iam_ip: "10.0.0.13" shared_service_keycloak_ip: "10.0.0.6" shared_service_mail_ip: "10.0.0.8" -shared_service_maria_ip: "10.0.0.19" +shared_service_maria_ip: "10.0.0.11" shared_service_pg_master_ip: "10.0.0.17" shared_service_pg_slave_ip: "10.0.0.18" shared_service_webdav_ip: "10.0.0.16" diff --git a/roles/connect-wordpress-maria/defaults/main.yml b/roles/connect-wordpress-maria/defaults/main.yml new file mode 100644 index 0000000..3933735 --- /dev/null +++ b/roles/connect-wordpress-maria/defaults/main.yml @@ -0,0 +1,18 @@ +--- + +mysql_databases: [ + { + name: "{{ connect_wordpress_maria_database_name }}", + collation: "utf8_general_ci", + encoding: "utf8", + } +] + +mysql_users: [ + { + name: "{{ connect_wordpress_maria_username }}", + host: "%", + password: "{{ connect_wordpress_maria_password }}", + priv: "{{ connect_wordpress_maria_database_name }}.*:ALL", + } +] diff --git a/roles/connect-wordpress-maria/handlers/main.yml b/roles/connect-wordpress-maria/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/connect-wordpress-maria/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/connect-wordpress-maria/meta/main.yml b/roles/connect-wordpress-maria/meta/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/connect-wordpress-maria/meta/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/connect-wordpress-maria/tasks/main.yml b/roles/connect-wordpress-maria/tasks/main.yml new file mode 100644 index 0000000..32d195e --- /dev/null +++ b/roles/connect-wordpress-maria/tasks/main.yml @@ -0,0 +1,32 @@ +--- + +- name: "Send mattermost message" + uri: + url: "{{ mattermost_hook_smardigo }}" + method: POST + body: "{{ lookup('template','mattermost-deploy-start.json.j2') }}" + body_format: json + headers: + Content-Type: "application/json" + delegate_to: 127.0.0.1 + become: false + when: + - send_status_messages + +- name: "Setup maria for {{ service_name }}" + include_role: + name: maria + tasks_from: _create-database + +- name: "Send mattermost messsge" + uri: + url: "{{ mattermost_hook_smardigo }}" + method: POST + body: "{{ lookup('template','mattermost-deploy-end.json.j2') }}" + body_format: json + headers: + Content-Type: "application/json" + delegate_to: 127.0.0.1 + become: false + when: + - send_status_messages diff --git a/roles/connect-wordpress-maria/vars/main.yml b/roles/connect-wordpress-maria/vars/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/connect-wordpress-maria/vars/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/maria/defaults/main.yml b/roles/maria/defaults/main.yml index 091ca6a..ed97d53 100644 --- a/roles/maria/defaults/main.yml +++ b/roles/maria/defaults/main.yml @@ -1,2 +1 @@ --- -mysql_root_password: "abc123" diff --git a/roles/maria/tasks/_create-database.yml b/roles/maria/tasks/_create-database.yml new file mode 100644 index 0000000..0bfabf3 --- /dev/null +++ b/roles/maria/tasks/_create-database.yml @@ -0,0 +1,50 @@ +--- + +- name: "Send mattermost message" + uri: + url: "{{ mattermost_hook_smardigo }}" + method: POST + body: "{{ lookup('template','mattermost-deploy-start.json.j2') }}" + body_format: json + headers: + Content-Type: "application/json" + delegate_to: 127.0.0.1 + become: false + when: + - send_status_messages + +- name: Ensure MySQL databases are present. + mysql_db: + name: "{{ item.name }}" + collation: "{{ item.collation | default('utf8_general_ci') }}" + encoding: "{{ item.encoding | default('utf8') }}" + state: "{{ item.state | default('present') }}" + config_file: "/etc/mysql/mariadb.conf.d/50-client.cnf" + login_password: "{{ mysql_root_password }}" + with_items: "{{ mysql_databases }}" + +- name: Ensure MySQL users are present. + mysql_user: + name: "{{ item.name }}" + password: "{{ item.password }}" + priv: "{{ item.priv | default('*.*:USAGE') }}" + state: "{{ item.state | default('present') }}" + append_privs: "{{ item.append_privs | default('no') }}" + encrypted: "{{ item.encrypted | default('no') }}" + config_file: "/etc/mysql/mariadb.conf.d/50-client.cnf" + login_password: "{{ mysql_root_password }}" + host: "{{ item.host }}" + with_items: "{{ mysql_users }}" + +- name: "Send mattermost messsge" + uri: + url: "{{ mattermost_hook_smardigo }}" + method: POST + body: "{{ lookup('template','mattermost-deploy-end.json.j2') }}" + body_format: json + headers: + Content-Type: "application/json" + delegate_to: 127.0.0.1 + become: false + when: + - send_status_messages