From f2df9c06f764152c99c60c44069f117badc6715b Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 20 Oct 2024 22:22:18 +0200 Subject: [PATCH] refactor ghost --- playbooks/apps/all.yaml | 3 +- playbooks/apps/bin.yaml | 2 +- playbooks/apps/ghost-update.yaml | 44 ------------------- .../apps/{ghost-config.yaml => ghost.yaml} | 30 ++++++------- .../apps/templates/bin/dump-gabnotes.org.j2 | 2 +- .../bin/dump-voyages-lois.augendre.info.j2 | 2 +- .../bin/dump-voyages.coccomagnard.fr.j2 | 2 +- .../gabnotes-org-config.json.j2 | 4 +- .../voyages-coccomagnard-fr-config.json.j2 | 4 +- .../voyages-lois-augendre-info-config.json.j2 | 4 +- roles/ghost/defaults/main.yaml | 5 +++ roles/ghost/handlers/main.yaml | 6 +++ roles/ghost/tasks/main.yaml | 19 ++++++++ roles/ghost_setup/defaults/main.yaml | 5 --- roles/ghost_setup/handlers/main.yaml | 6 --- roles/ghost_setup/tasks/main.yaml | 14 ------ 16 files changed, 56 insertions(+), 96 deletions(-) delete mode 100644 playbooks/apps/ghost-update.yaml rename playbooks/apps/{ghost-config.yaml => ghost.yaml} (84%) rename playbooks/apps/templates/{ghost-config => ghost}/gabnotes-org-config.json.j2 (88%) rename playbooks/apps/templates/{ghost-config => ghost}/voyages-coccomagnard-fr-config.json.j2 (88%) rename playbooks/apps/templates/{ghost-config => ghost}/voyages-lois-augendre-info-config.json.j2 (88%) create mode 100644 roles/ghost/defaults/main.yaml create mode 100644 roles/ghost/handlers/main.yaml create mode 100644 roles/ghost/tasks/main.yaml delete mode 100644 roles/ghost_setup/defaults/main.yaml delete mode 100644 roles/ghost_setup/handlers/main.yaml delete mode 100644 roles/ghost_setup/tasks/main.yaml diff --git a/playbooks/apps/all.yaml b/playbooks/apps/all.yaml index 9c7fd92..b6cd1c3 100644 --- a/playbooks/apps/all.yaml +++ b/playbooks/apps/all.yaml @@ -6,8 +6,7 @@ - import_playbook: code.yaml # noqa: name[play] - import_playbook: collabora.yaml # noqa: name[play] - import_playbook: display.yaml # noqa: name[play] -- import_playbook: ghost-config.yaml # noqa: name[play] -- import_playbook: ghost-update.yaml # noqa: name[play] +- import_playbook: ghost.yaml # noqa: name[play] - import_playbook: git.yaml # noqa: name[play] - import_playbook: goatcounter.yaml # noqa: name[play] - import_playbook: lyon-transports.yaml # noqa: name[play] diff --git a/playbooks/apps/bin.yaml b/playbooks/apps/bin.yaml index 8c1f8b2..93d3f87 100644 --- a/playbooks/apps/bin.yaml +++ b/playbooks/apps/bin.yaml @@ -18,7 +18,7 @@ with_fileglob: - templates/bin/*.j2 vars: - ghost_setup_db_password: !vault | + ghost_db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 35343430343439653064613033383830396264306538376535346637613166376663393062353132 6537386534656239333731313938653539643165323532380a336162663839303339623266383662 diff --git a/playbooks/apps/ghost-update.yaml b/playbooks/apps/ghost-update.yaml deleted file mode 100644 index 8d99502..0000000 --- a/playbooks/apps/ghost-update.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- name: Ghost update - hosts: servers - gather_facts: false - tasks: - # Run the first task synchronously to download dependencies. - - name: Update gabnotes.org - ansible.builtin.command: - chdir: /mnt/data/gabnotes.org - cmd: ghost update - register: gabnotes - changed_when: '"Restarting Ghost" in gabnotes.stdout' - - name: Start update on voyages-lois.augendre.info - ansible.builtin.command: - chdir: /mnt/data/voyages-lois.augendre.info - cmd: ghost update - register: voyages_lois_async - changed_when: false - async: 300 - poll: 0 - - name: Start update on voyages.coccomagnard.fr - ansible.builtin.command: - chdir: /mnt/data/voyages.coccomagnard.fr - cmd: ghost update - register: voyages_coccomagnard_async - changed_when: false - async: 300 - poll: 0 - - name: Check voyages-lois.augendre.info - ansible.builtin.async_status: - jid: "{{ voyages_lois_async.ansible_job_id }}" - register: voyages_lois - until: voyages_lois.finished - changed_when: '"Restarting Ghost" in voyages_lois.stdout' - retries: 100 - delay: 10 - - name: Check voyages.coccomagnard.fr - ansible.builtin.async_status: - jid: "{{ voyages_coccomagnard_async.ansible_job_id }}" - register: voyages_coccomagnard - until: voyages_coccomagnard.finished - changed_when: '"Restarting Ghost" in voyages_coccomagnard.stdout' - retries: 100 - delay: 10 diff --git a/playbooks/apps/ghost-config.yaml b/playbooks/apps/ghost.yaml similarity index 84% rename from playbooks/apps/ghost-config.yaml rename to playbooks/apps/ghost.yaml index b70197e..cd12c2e 100644 --- a/playbooks/apps/ghost-config.yaml +++ b/playbooks/apps/ghost.yaml @@ -5,18 +5,18 @@ tasks: - name: Setup ghost gabnotes.org ansible.builtin.include_role: - name: ghost_setup + name: ghost vars: - ghost_setup_filename: gabnotes-org-config.json.j2 - ghost_setup_site: gabnotes.org - ghost_setup_db_password: !vault | + ghost_filename: gabnotes-org-config.json.j2 + ghost_site: gabnotes.org + ghost_db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 66306233626430393737653333313461666665363936376465623137656561356431373666363032 6537313234336331626464336434343462623264633463330a353165396163653666636333633537 33353464393836623861633238663336336465326435613638613734613433386537663635666332 6338343039393737310a356335666632303062353336613364323165633239323032346239376262 32323862393264326162383761653163353731363331326337633461643364373936 - ghost_setup_mail_password: !vault | + ghost_mail_password: !vault | $ANSIBLE_VAULT;1.1;AES256 61313164316335333431656136326636353535643363623665326565303961356234353362646261 3339616561643434376163613962366631303863313263310a323330316230333864636232386632 @@ -27,18 +27,18 @@ 373032363533393263323835363666623966 - name: Setup ghost voyages.coccomagnard.fr ansible.builtin.include_role: - name: ghost_setup + name: ghost vars: - ghost_setup_filename: voyages-coccomagnard-fr-config.json.j2 - ghost_setup_site: voyages.coccomagnard.fr - ghost_setup_db_password: !vault | + ghost_filename: voyages-coccomagnard-fr-config.json.j2 + ghost_site: voyages.coccomagnard.fr + ghost_db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 33623632396330303536366136313438623138366231333063613539303538303761386264623239 3266366633343936356564636131303939636330336335390a313430346536666239656562393238 32373533373663656435306239643638313937623631366262393462306138323061333961363938 3239373062613138660a393933393436633166303837303263356232336666386336346366373934 38346330616639646666616161613865643461643965333237353936663933336533 - ghost_setup_mail_password: !vault | + ghost_mail_password: !vault | $ANSIBLE_VAULT;1.1;AES256 33386530613164633962393133316231613664623761336237353335336430313637356430306430 3837373934336361636461343338643737653839396336340a633130613038666534653865303338 @@ -49,18 +49,18 @@ 656136646536333065616631336235623430 - name: Setup ghost voyages-lois.augendre.info ansible.builtin.include_role: - name: ghost_setup + name: ghost vars: - ghost_setup_filename: voyages-lois-augendre-info-config.json.j2 - ghost_setup_site: voyages-lois.augendre.info - ghost_setup_db_password: !vault | + ghost_filename: voyages-lois-augendre-info-config.json.j2 + ghost_site: voyages-lois.augendre.info + ghost_db_password: !vault | $ANSIBLE_VAULT;1.1;AES256 30623130336131633738353931653239623133326265363862353530303232633333383462663330 3935333936383663326162653864623630396363666131390a393532336531663262616431396165 33303236363739636665616636326262336532623234666263363563633962343734613565373031 3139313038663432370a623363366436643862343734393334306162376634366637616536303035 32653739373732613930376336636332343333643436633261616561633034623566 - ghost_setup_mail_password: !vault | + ghost_mail_password: !vault | $ANSIBLE_VAULT;1.1;AES256 35353737376566653462393530613034353763643166626432613836663638636562303762343133 6132313762353565646531613336663336313765623430310a616438613433333632343933373330 diff --git a/playbooks/apps/templates/bin/dump-gabnotes.org.j2 b/playbooks/apps/templates/bin/dump-gabnotes.org.j2 index b2f3540..0538df0 100755 --- a/playbooks/apps/templates/bin/dump-gabnotes.org.j2 +++ b/playbooks/apps/templates/bin/dump-gabnotes.org.j2 @@ -1,3 +1,3 @@ #!/bin/bash set -euo pipefail -/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_setup_db_password }} gabnotes_org_prod > /mnt/data/gabnotes.org/db_export/backup.sql +/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_db_password }} gabnotes_org_prod > /mnt/data/gabnotes.org/db_export/backup.sql diff --git a/playbooks/apps/templates/bin/dump-voyages-lois.augendre.info.j2 b/playbooks/apps/templates/bin/dump-voyages-lois.augendre.info.j2 index 1ab19f9..86f763c 100755 --- a/playbooks/apps/templates/bin/dump-voyages-lois.augendre.info.j2 +++ b/playbooks/apps/templates/bin/dump-voyages-lois.augendre.info.j2 @@ -1,3 +1,3 @@ #!/bin/bash set -euo pipefail -/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_setup_db_password }} voyages_lois_augendre_info_prod > /mnt/data/voyages-lois.augendre.info/db_export/backup.sql +/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_db_password }} voyages_lois_augendre_info_prod > /mnt/data/voyages-lois.augendre.info/db_export/backup.sql diff --git a/playbooks/apps/templates/bin/dump-voyages.coccomagnard.fr.j2 b/playbooks/apps/templates/bin/dump-voyages.coccomagnard.fr.j2 index 166a24c..aa2e308 100755 --- a/playbooks/apps/templates/bin/dump-voyages.coccomagnard.fr.j2 +++ b/playbooks/apps/templates/bin/dump-voyages.coccomagnard.fr.j2 @@ -1,3 +1,3 @@ #!/bin/bash set -euo pipefail -/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_setup_db_password }} voyages_coccomagnard_fr_prod > /mnt/data/voyages.coccomagnard.fr/db_export/backup.sql +/usr/bin/mysqldump --no-tablespaces -u root --password={{ ghost_db_password }} voyages_coccomagnard_fr_prod > /mnt/data/voyages.coccomagnard.fr/db_export/backup.sql diff --git a/playbooks/apps/templates/ghost-config/gabnotes-org-config.json.j2 b/playbooks/apps/templates/ghost/gabnotes-org-config.json.j2 similarity index 88% rename from playbooks/apps/templates/ghost-config/gabnotes-org-config.json.j2 rename to playbooks/apps/templates/ghost/gabnotes-org-config.json.j2 index ec34a06..4d00484 100644 --- a/playbooks/apps/templates/ghost-config/gabnotes-org-config.json.j2 +++ b/playbooks/apps/templates/ghost/gabnotes-org-config.json.j2 @@ -12,7 +12,7 @@ "connection": { "host": "127.0.0.1", "user": "ghost-900", - "password": "{{ ghost_setup_db_password }}", + "password": "{{ ghost_db_password }}", "database": "gabnotes_org_prod" } }, @@ -26,7 +26,7 @@ "secure": true, "auth": { "user": "blog@mg.gabnotes.org", - "pass": "{{ ghost_setup_mail_password }}" + "pass": "{{ ghost_mail_password }}" } } }, diff --git a/playbooks/apps/templates/ghost-config/voyages-coccomagnard-fr-config.json.j2 b/playbooks/apps/templates/ghost/voyages-coccomagnard-fr-config.json.j2 similarity index 88% rename from playbooks/apps/templates/ghost-config/voyages-coccomagnard-fr-config.json.j2 rename to playbooks/apps/templates/ghost/voyages-coccomagnard-fr-config.json.j2 index 0fe1f31..48354e3 100644 --- a/playbooks/apps/templates/ghost-config/voyages-coccomagnard-fr-config.json.j2 +++ b/playbooks/apps/templates/ghost/voyages-coccomagnard-fr-config.json.j2 @@ -9,7 +9,7 @@ "connection": { "host": "127.0.0.1", "user": "ghost-310", - "password": "{{ ghost_setup_db_password }}", + "password": "{{ ghost_db_password }}", "database": "voyages_coccomagnard_fr_prod" } }, @@ -23,7 +23,7 @@ "secure": true, "auth": { "user": "voyages@mg.coccomagnard.fr", - "pass": "{{ ghost_setup_mail_password }}" + "pass": "{{ ghost_mail_password }}" } } }, diff --git a/playbooks/apps/templates/ghost-config/voyages-lois-augendre-info-config.json.j2 b/playbooks/apps/templates/ghost/voyages-lois-augendre-info-config.json.j2 similarity index 88% rename from playbooks/apps/templates/ghost-config/voyages-lois-augendre-info-config.json.j2 rename to playbooks/apps/templates/ghost/voyages-lois-augendre-info-config.json.j2 index 25059e9..752545a 100644 --- a/playbooks/apps/templates/ghost-config/voyages-lois-augendre-info-config.json.j2 +++ b/playbooks/apps/templates/ghost/voyages-lois-augendre-info-config.json.j2 @@ -9,7 +9,7 @@ "connection": { "host": "127.0.0.1", "user": "ghost-483", - "password": "{{ ghost_setup_db_password }}", + "password": "{{ ghost_db_password }}", "database": "voyages_lois_augendre_info_prod" } }, @@ -23,7 +23,7 @@ "secure": true, "auth": { "user": "voyages-lois@mg.augendre.info", - "pass": "{{ ghost_setup_mail_password }}" + "pass": "{{ ghost_mail_password }}" } } }, diff --git a/roles/ghost/defaults/main.yaml b/roles/ghost/defaults/main.yaml new file mode 100644 index 0000000..2be4a55 --- /dev/null +++ b/roles/ghost/defaults/main.yaml @@ -0,0 +1,5 @@ +--- +ghost_filename: site-com-config.json.j2 +ghost_site: site.com +ghost_db_password: 123 +ghost_mail_password: 123 diff --git a/roles/ghost/handlers/main.yaml b/roles/ghost/handlers/main.yaml new file mode 100644 index 0000000..1d616b0 --- /dev/null +++ b/roles/ghost/handlers/main.yaml @@ -0,0 +1,6 @@ +--- +- name: Restart service {{ ghost_site }} + ansible.builtin.command: + cmd: ghost restart + chdir: /mnt/data/{{ ghost_site }} + changed_when: true diff --git a/roles/ghost/tasks/main.yaml b/roles/ghost/tasks/main.yaml new file mode 100644 index 0000000..edd0edf --- /dev/null +++ b/roles/ghost/tasks/main.yaml @@ -0,0 +1,19 @@ +--- +- name: Write config files for {{ ghost_site }} + ansible.builtin.template: + src: templates/ghost/{{ ghost_filename }} + dest: /mnt/data/{{ ghost_site }}/config.production.json + mode: "0664" + notify: + - Restart service +- name: Ensure service is started {{ ghost_site }} + ansible.builtin.command: + cmd: ghost start + chdir: /mnt/data/{{ ghost_site }} + register: start + changed_when: '"Starting Ghost" in start.stdout' +- name: Update {{ ghost_site }} + ansible.builtin.command: + cmd: ghost update + chdir: /mnt/data/{{ ghost_site }} + changed_when: '"Restarting Ghost" in gabnotes.stdout' diff --git a/roles/ghost_setup/defaults/main.yaml b/roles/ghost_setup/defaults/main.yaml deleted file mode 100644 index 254330b..0000000 --- a/roles/ghost_setup/defaults/main.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -ghost_setup_filename: site-com-config.json.j2 -ghost_setup_site: site.com -ghost_setup_db_password: 123 -ghost_setup_mail_password: 123 diff --git a/roles/ghost_setup/handlers/main.yaml b/roles/ghost_setup/handlers/main.yaml deleted file mode 100644 index 8d68f1f..0000000 --- a/roles/ghost_setup/handlers/main.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Restart service - ansible.builtin.command: - cmd: ghost restart - chdir: /mnt/data/{{ ghost_setup_site }} - changed_when: true diff --git a/roles/ghost_setup/tasks/main.yaml b/roles/ghost_setup/tasks/main.yaml deleted file mode 100644 index 2a34c2e..0000000 --- a/roles/ghost_setup/tasks/main.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Write config files - ansible.builtin.template: - src: templates/ghost-config/{{ ghost_setup_filename }} - dest: /mnt/data/{{ ghost_setup_site }}/config.production.json - mode: "0664" - notify: - - Restart service -- name: Ensure service is started - ansible.builtin.command: - cmd: ghost start - chdir: /mnt/data/{{ ghost_setup_site }} - register: start - changed_when: '"Starting Ghost" in start.stdout'