From b9b59122d3ab1f7a32c62174f3bf626f25e0ef31 Mon Sep 17 00:00:00 2001 From: Dryusdan Date: Sun, 24 Jan 2021 16:49:42 +0100 Subject: [PATCH] First commit --- example.yml | 19 +++ tasks/main.yml | 185 +++++++++++++++++++++++ templates/.config.production.json.j2.swp | Bin 0 -> 12288 bytes templates/config.production.json.j2 | 57 +++++++ templates/systemd.service.j2 | 16 ++ 5 files changed, 277 insertions(+) create mode 100644 example.yml create mode 100644 tasks/main.yml create mode 100644 templates/.config.production.json.j2.swp create mode 100644 templates/config.production.json.j2 create mode 100644 templates/systemd.service.j2 diff --git a/example.yml b/example.yml new file mode 100644 index 0000000..869946c --- /dev/null +++ b/example.yml @@ -0,0 +1,19 @@ +ghost: + - name: dryusdan.space + account: dryusdan_space + home: /opt/dryusdan_space + url: dryusdan.space + ghost_host: 127.0.0.1 + ghost_port: 7777 + db_host: 127.0.0.1 + db_port: 3306 + db_user: dryusdanspace + db_password: Password + db: dryusdanspace + email_send: True + email_from: contact@dryusdan.fr + email_host: 127.0.0.1 + email_port: 587 + email_user: contact@dryusdan.fr + email_pass: Password + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..10fdf18 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,185 @@ +--- +- 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.key + +- 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.key + +- 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.key + +- name: "Delete www" + file: + path: "{{ item.home }}/www" + state: absent + loop: "{{ ghost }}" + when: ghost_deploy_site in item.key + +- 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.key + +- name: "Unzip content folder Ghost" + shell: "unzip -o ghost-latest.zip 'content/*' -d ./" + args: + chdir: "{{ item.home }}/" + with_dict: "{{ ghost }}" + become: yes + become_user : "{{ item.account }}" + when: ghost_deploy_site in item.key + +- name: "Delete content" + file: + path: "{{ item.home }}/www/content" + state: absent + loop: "{{ ghost }}" + when: ghost_deploy_site in item.key + +- 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.key + 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.key + +- name: "Config daemon" + template: + src: "systemd.service.j2" + dest: "/etc/systemd/system/{{ item.name }}.service" + loop: "{{ ghost }}" + when: ghost_deploy_site in item.key + +- 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.key + +- 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.key + +- 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.key + +- 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.key + +- 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.key + +- name: "Restart service" + systemd: + name: "{{ item.name }}.service" + state: restarted + loop: "{{ ghost }}" + when: ghost_deploy_site in item.key + +- name: "Delete archive" + file: + path: "{{ item.home }}/ghost-latest.zip" + state: absent + loop: "{{ ghost }}" + when: ghost_deploy_site in item.key + +- 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.key + +- 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.key diff --git a/templates/.config.production.json.j2.swp b/templates/.config.production.json.j2.swp new file mode 100644 index 0000000000000000000000000000000000000000..7bb94c23914b5b82dfe232ba53cb7c7b40aeaf77 GIT binary patch literal 12288 zcmeI2!D|#r6vj)Bt1)88$xGQ1@SxKsBE*1;hlM4YK+xz#M0=)dCapbPy;ao-!!R!5 zQSh*b_29*mUIgzVNMQG_9=s}hSeAwT4;Jxz)!oU=#00O(YxugSU%mJ0)vsP3LaKTC z+TyaDZ_El@hlRNC`^2ry>4xYo3K3;CX{L%s_Pmyhv=N(LVdE%kw9T%*cdLY9o<_Z< z)_20rnzk-ws`^2wU%>HUY=c?zvv1j$l4<^6_ zm;e)C0!)AjFaajO1egF5U;<3w8zd0LLM;9O9YFE;|9}1W|EEbIK0vRa7tjM}0BL9m zIsqMrrl9{13Gol~2lNDT&}C=|`Wc#sBy<#-g#Min;w|(XdJGxp5_Aqa2z@*##Czxs zvyZgl-Koy{)-1B9WKk{-$vn(w#!KfB6J?RD!LGP~9j=Z;}<;Qj;K0OjcNB zXr57DvXXDj2#!(V7h1ybp~Rh*Qf+%R3yg>y3Z%2oJ7*y4_6&i}33lBbn67PfcV`q? zhoVMEU0GgTsR{-t@bt}CR%Jn0oF(NZP8fS6GAVynSCjMXG-Yd=EGfWaU)$$Hf4 zjr!KagE(?gGqP&9*0@PEB9<<6h_xHq_(rT*#ZA8*WZqs5e8+bKe&bsajPr!g7)*S0 z8JcFKds}Hj-ywFo+q1u