From cf6baa71e503e87cabd996b93353b13b177aa581 Mon Sep 17 00:00:00 2001 From: Dryusdan Date: Mon, 2 May 2022 17:48:54 +0200 Subject: [PATCH] Improve Ghost playbook --- tasks/main.yml | 193 ++-------------------------- templates/config.production.json.j2 | 9 +- templates/systemd.service.j2 | 5 +- 3 files changed, 16 insertions(+), 191 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index ace78e9..adce842 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,185 +1,16 @@ --- -- name: "Add ghost user" - user: - name: "{{ item.account }}" - shell: "/bin/false" - home: "{{ item.home }}" - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name +- include_tasks: install.yml + when: ansible_os_family == 'Debian' + tags: + - install -- name: "Add www directory" - file: - path: "{{ item.home }}/www" - state: directory - mode: 0755 - owner: "{{ item.account }}" - group: "{{ item.account }}" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name +- include_tasks: configure.yml + when: ansible_os_family == 'Debian' + tags: + - configure -- name: "Add blog log directory" - file: - path: "/var/log/ghost/" - state: directory - mode: 0755 +- include_tasks: update.yml + when: ansible_os_family == 'Debian' + tags: + - update -- name: "Add blog log directory" - file: - path: "/var/log/ghost/{{ item.name }}/" - state: directory - mode: 0755 - owner: "{{ item.account }}" - group: "{{ item.account }}" - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Download Ghost" - get_url: - url: "https://github.com/TryGhost/Ghost/releases/download/v{{ version }}/Ghost-{{ version }}.zip" - dest: "{{ item.home }}/ghost-latest.zip" - mode: 0440 - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Delete www" - file: - path: "{{ item.home }}/www" - state: absent - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Unzip Ghost" - shell: "unzip -o ghost-latest.zip -d www" - args: - chdir: "{{ item.home }}/" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Unzip content folder Ghost" - shell: "unzip -o ghost-latest.zip 'content/*' -d ./" - args: - chdir: "{{ item.home }}/" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Delete content" - file: - path: "{{ item.home }}/www/content" - state: absent - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Symlink content" - file: - src: "{{ item.home }}/content" - dest: "{{ item.home }}/www/content" - state: link - owner: "{{ item.account }}" - group: "{{ item.account }}" - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - become: yes - become_user : "{{ item.account }}" - -- name: "Config ghost" - template: - src: "config.production.json.j2" - dest: "{{ item.home }}/www/config.production.json" - owner: "{{ item.account }}" - group: "{{ item.account }}" - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Config daemon" - template: - src: "systemd.service.j2" - dest: "/etc/systemd/system/{{ item.name }}.service" - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Install node modules" - shell: "NODE_ENV=production npm i" - args: - chdir: "{{ item.home }}/www" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Install yarn module" - shell: "NODE_ENV=production yarn install" - args: - chdir: "{{ item.home }}/www" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Knex init" - shell: "NODE_ENV=production node_modules/knex-migrator/bin/knex-migrator init" - args: - chdir: "{{ item.home }}/www" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Knex migrate" - shell: "NODE_ENV=production node_modules/knex-migrator/bin/knex-migrator migrate" - args: - chdir: "{{ item.home }}/www" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "Reload systemctl" - systemd: - daemon_reload: yes - -- name: "Enable service" - systemd: - name: "{{ item.name }}.service" - enabled: yes - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Restart service" - systemd: - name: "{{ item.name }}.service" - state: restarted - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Delete archive" - file: - path: "{{ item.home }}/ghost-latest.zip" - state: absent - loop: "{{ ghost }}" - when: ghost_deploy_site in item.name - -- name: "Clean cache yarn" - shell: "yarn cache clean" - args: - chdir: "{{ item.home }}/" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name - -- name: "NPM Cache clean" - shell: "npm cache clean --force" - args: - chdir: "{{ item.home }}/" - loop: "{{ ghost }}" - become: yes - become_user : "{{ item.account }}" - when: ghost_deploy_site in item.name diff --git a/templates/config.production.json.j2 b/templates/config.production.json.j2 index 8ad4597..c822d0a 100644 --- a/templates/config.production.json.j2 +++ b/templates/config.production.json.j2 @@ -43,19 +43,12 @@ }, {% endif %} "logging": { - "path": "/var/log/ghost/{{ item.name }}/", "level": "error", - "rotation": { - "enabled": true, - "count": 15, - "period": "1d" - }, "transports": [ - "file" + "stdout" ] }, "compress": true, - "process": "systemd", "paths": { "contentPath": "{{ item.home }}/www/content" }, diff --git a/templates/systemd.service.j2 b/templates/systemd.service.j2 index 02b4729..38fe374 100644 --- a/templates/systemd.service.j2 +++ b/templates/systemd.service.j2 @@ -1,13 +1,14 @@ [Unit] Description=Ghost blog for {{ item.name }} After=network.target + After=mariadb.service [Service] Type=simple User={{ item.account }} - WorkingDirectory={{ item.home }}/www/ + WorkingDirectory={{ item.home }} Environment="NODE_ENV=production" - ExecStart=/usr/bin/node index.js + ExecStart=/opt/{{ item.home }}/node_modules/.bin/ghost run --dir www TimeoutSec=15 Restart=always