From c822168ea26efd973ec2e0e6cdd95846b5569ab6 Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Fri, 15 Sep 2023 22:01:42 +0200 Subject: [PATCH] Setup mysql on the loadbalancer --- ansible/playbook.yaml | 19 ++-- ansible/roles/mysql/tasks/main.yaml | 15 +++ ansible/roles/mysql/templates/mysql.cnf.j2 | 2 + ansible/roles/wordpress/tasks/main.yaml | 1 + .../wordpress/templates/wp-config.php.j2 | 2 +- ansible/vault.yaml | 97 ++++++++++--------- 6 files changed, 76 insertions(+), 60 deletions(-) create mode 100644 ansible/roles/mysql/templates/mysql.cnf.j2 diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index fb50867..8dcf8ea 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -36,6 +36,8 @@ - name: Setup loadbalancer hosts: lb + vars_files: + - vault.yaml vars: caddy: server_name: wordpress-jr.senecops.com @@ -43,8 +45,11 @@ - 10.0.0.3:80 - 10.0.0.4:80 - 10.0.0.5:80 + mysql: + hostrange: "10.0.0.0/255.255.255.0" roles: - caddy + - mysql - name: Setup LEMP stack on application servers hosts: web @@ -54,8 +59,6 @@ server_name: wordpress-jr.senecops.com wordpress: dir: /var/www/html/wordpress - db_name: wordpress - db_user: wp php: version: 8.1 gluster: @@ -68,20 +71,10 @@ - 10.0.0.3 - 10.0.0.4 - 10.0.0.5 - mysql: - replication_user: replica_user - replication_master_hostname: web1 - replication_master_ip: 10.0.0.3 - replication_slaves: - - web2 - - web3 pre_tasks: - - debug: var=ansible_all_ipv4_addresses - # we need gluster on all servers to configure peering + - debug: var=ansible_ens10.ipv4.address roles: - nginx - - mysql - - mysql-replication - php - glusterfs - wordpress diff --git a/ansible/roles/mysql/tasks/main.yaml b/ansible/roles/mysql/tasks/main.yaml index e9154fe..26ac260 100644 --- a/ansible/roles/mysql/tasks/main.yaml +++ b/ansible/roles/mysql/tasks/main.yaml @@ -10,6 +10,13 @@ state: present become: true +- name: Write config + ansible.builtin.template: + src: "mysql.cnf.j2" + dest: "/etc/mysql/mariadb.conf.d/50-server.cnf" + mode: "0644" + become: true + - name: Set new root user password community.mysql.mysql_user: name: root @@ -25,6 +32,7 @@ login_user: root login_password: "{{ mysql_root_password }}" password: "{{ wordpress_db_pass }}" + host: "{{ mysql.hostrange }}" priv: "wordpress.*": "ALL,GRANT" login_unix_socket: /var/run/mysqld/mysqld.sock @@ -43,3 +51,10 @@ state: present login_unix_socket: /var/run/mysqld/mysqld.sock become: true + +- name: restart mysql + ansible.builtin.service: + name: mysql + state: restarted + enabled: true + become: true diff --git a/ansible/roles/mysql/templates/mysql.cnf.j2 b/ansible/roles/mysql/templates/mysql.cnf.j2 new file mode 100644 index 0000000..b23f214 --- /dev/null +++ b/ansible/roles/mysql/templates/mysql.cnf.j2 @@ -0,0 +1,2 @@ +[mysqld] +bind-address = "0.0.0.0" diff --git a/ansible/roles/wordpress/tasks/main.yaml b/ansible/roles/wordpress/tasks/main.yaml index 26bbd99..8575d8e 100644 --- a/ansible/roles/wordpress/tasks/main.yaml +++ b/ansible/roles/wordpress/tasks/main.yaml @@ -10,6 +10,7 @@ src: /tmp/wordpress.tar.gz dest: "{{ wordpress.dir | dirname }}" remote_src: true + creates: "index.php" run_once: true become: true diff --git a/ansible/roles/wordpress/templates/wp-config.php.j2 b/ansible/roles/wordpress/templates/wp-config.php.j2 index da15922..ed99d8a 100644 --- a/ansible/roles/wordpress/templates/wp-config.php.j2 +++ b/ansible/roles/wordpress/templates/wp-config.php.j2 @@ -44,7 +44,7 @@ define( 'DB_PASSWORD', '{{ wordpress_db_pass }}' ); /** * Ersetze localhost mit der Datenbank-Serveradresse. */ -define( 'DB_HOST', 'localhost' ); +define( 'DB_HOST', '{{ wordpress.db_host}}' ); /** * Der Datenbankzeichensatz, der beim Erstellen der diff --git a/ansible/vault.yaml b/ansible/vault.yaml index 0a4d918..3ba69e7 100644 --- a/ansible/vault.yaml +++ b/ansible/vault.yaml @@ -1,47 +1,52 @@ $ANSIBLE_VAULT;1.1;AES256 -35643435643566346466373336656430653736616533613430303662613532633737643436656565 -6464366565333938376361393565353965383265386631620a303038376162333866323035643239 -62343237643233643135633137633564633464613736656532383336633566633832373066343039 -3039313331343065610a626135326638306363643538383337656632613561333561643664623861 -34373261356537363739663263623264343663383565643062323333303138373066363135363132 -62646437636332323634333739303839306532653733626332316234313935633132656463363937 -32653865653166646566613965373434656437633531643138376539656166346233653531613363 -32643736616231646534303738653864303735346339396139623833376163383030643538373034 -34663438343633333765346236393832333433373633353466386536653539316435306134636533 -61333637656431316230636135633835653031326665303364653766383832303430626436663936 -32356261386534306562626235336338326530373635633730663263373733336630383836343461 -37363737646165643736636637633063666562303332353466313739386635666163353165636337 -36326637343261393361303266343332643436386565333330656432636363316138303464643339 -34386165666633366439643937376139663530306631633737636537313862346562353139326665 -36666166333139393337353266626562653136623965343563383238373935653835326335363262 -31303037646663373062316432346439666230643966663039616266633930653139613163396131 -36346438316363383434363739653637393633303330666531626362326465616638653964313731 -31316533663030616339383465363135633463653733636230333462323562333866323437646264 -35633631383463656134363338633430386163393230353938373262306436656563343031363562 -36633762633666343835376261383361363536373836656466613338313633383961396566343763 -32396533643231316666366532636361376238303466653539666439326633363830366234336231 -32366663633436663436626262666633633739366234376334643139633666326639363362643263 -62326337643536323433613938613236306538316532643261383134396333646562613163343062 -33346230363232363935313531383866646232326162396264666162653362633666333333366562 -61383065653039646461306338663235303437313634666636353336663238336363393236663664 -30306532633061613966303334363934663232646339653534616539633839646466373664363830 -39386538626230306531333136653762666366306532303739363962333231373962653263653039 -62356536636537613930623438323934623631316334386665643065326562393065306664626639 -38333664393861653530396533373761353336363131306539333032643235386332326336393666 -34353039653234346334383338396664393535653835323733363038353062666339383533363938 -34303234393731643837313262616236613061663365316161396536363164396565663533373530 -37623833343364653963626131666235383462653964633937356161363830333737383635373163 -62666362353234633830653230306638363238666361356135653362356237613764346337663536 -65343234306530376434646532633833373365316166303536633330323366393335383035316332 -33616263656432633033353733626562633135396434633135623962303661393537366566306132 -61356663623237636432373733336261653262303038383063363838636638346134376437613539 -33313132636465666130653634623361363930383535393736613463626532366639343139393133 -33396432613834373732306439396561623839666630343731393765616431376631353834646239 -34316434313535626538306430323231363639383861323030656339376563386539303563623265 -36313933626538353333326266353233393336653434346437383834376136376337663466623561 -36633037643864326164646262383534333434373338323834653135613135396637376239663264 -38633330366130363930313932356430623862323737343165393035646364386436613365613564 -34306564643331343039643236396232336332326333636264623632386432393865666538313034 -32636361396663356637336435626135363661663536376136366632616635643233623762316463 -39343964323639323832323963373264303162663334393163396361356234356336633538623764 -6132343932373562653931613737366635323931346264633233 +32376361363364313165326638386266343838303437663430373636326339613764623561343139 +3734623739363563383436333563396365373636383736310a333139643763633861636434356237 +33363865303733336533333930633533376664336163386438373834326566666464343935363532 +6338663065653138640a386164393137663862316632363332363664616166363335643536643561 +31643435313739376462386361336636346335376365353564343865396163373761386136313733 +36323363313064663630623833396366303561656338383834396430353266636632316237366563 +63333462363765356338333239356533633533663931363631623265386664323861373266336339 +32313935323265653761626166653939326532336137323034313833396236346433643562343630 +30343835353337333265393165326230323036313034336232613431333833393863396661613561 +37366334333538383538633933626136363335393332656464316435623530373137616431613534 +64303464623561303836666161353837303534383238363537626365636639386437356331656461 +34323634623764333465346662313638653438653332303363306562353736346535366162623633 +61343532656130326632373635343937386462373230613636663130373537613433336363376637 +30663935396635656165376265646666343165383832363033336565323336366531323562373962 +66383762343462666238663434316535366564383461326466636466653439363463323366316134 +61333032353834666437303735613038376666313663353866373231666564306466336237653337 +33323239313638343064656461313733636330303930366638313236383166346430346336373032 +33393935323130323232356234663962303634623836626562376637666262386662346230343039 +66383839303830353536326261663232336264393632333432353036353064306233313261626334 +31313432306131386330616464646566346437373462323263313234353035643434356565333265 +61393930633964383637373664643735656361616637663561356635303163646330393664393330 +33393832333833313762323234363430386230383438316431663763393033303432613766306266 +38396636623234373035633462366462613364636336386161636634363531616564366162323430 +65633230646265646263346665633863353664666231383962373964383530343761323561646237 +31383635323039326232336563346332346635386262306530643235343637643135386535613438 +33356262666339643563336636323230386334343139353333303932323163386539396564396136 +39303064343431666331663133653531316438386534393833333836613035366133613132653237 +38303930383438663364383633313464346632623137653162333535353936633064666138303035 +31616536333661323762366134623530396539623064633735366565366362636430636562343635 +30356465363034626562646532353133656166333931333536633763316632643764343834346230 +39373765306635613730313161323735336137303836306631316635303036303530393365363530 +36313838666233666430343936306439353838623234393762663163343439326665666365633230 +34333462353931333432336236653466663139353265353932353165326462336333386566613666 +36343663316166636231353237373834643039393730623864643462646666323761336234343030 +37666537356630313136336332653336656563386232383765363465363765346432623131303635 +35306334333865393730626130643465363566643162646137616563393539393562306266363639 +64313932643739306131613666366138633862393038336338326664633833323138386538393432 +33383032376633613166393936613661626466633430326635333435663838393663373238303232 +65316336353439663436656565656566363638613636356233646632313635653538373836383366 +66383132643033383162353639613762326533663564343331646561623535316135346136386232 +37643166386265393637376361326166613437663233326130626566396638646130643933626361 +32353030373061666661653230636163646134343537393032393833383938616661616237356633 +39343162383236643130613032343063386466313030626137306631643064393736336461633930 +38383034643736356535663062373864353966343264633766643939383530636364333634386664 +63356263646362616231323838616536323333363438633266313633626331613534306664356664 +39633033356537626665643238333362316163343638353266666663336238613734346339363939 +30353863306136653635306131336636643061373261313039663231373839363635646433353461 +37326532333736313539303839666462376464383633343262623833626363393265386539323862 +32666439303138643864343162383732663863393339353639303439343063616162333366353333 +64613563356230353137313434303034343866346130613263323635636164626134383461636231 +663135323339346161303731653835313562