ghost/tasks/main.yml

186 lines
4.4 KiB
YAML

---
- name: "Add ghost user"
user:
name: "{{ item.account }}"
shell: "/bin/false"
home: "{{ item.home }}"
loop: "{{ ghost }}"
when: ghost_deploy_site in item.name
- 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
- name: "Add blog log directory"
file:
path: "/var/log/ghost/"
state: directory
mode: 0755
- 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/{{ 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