Improve Ghost playbook

This commit is contained in:
Dryusdan 2022-05-02 17:48:54 +02:00
parent 4012495646
commit cf6baa71e5
3 changed files with 16 additions and 191 deletions

View File

@ -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

View File

@ -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"
},

View File

@ -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