From c099827d8816c12612b0823739dfedac4b863103 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Tue, 14 Apr 2020 11:30:40 +0200 Subject: [PATCH] Group plays to hooks --- plays/commonlib/vars.yml | 42 +++++++++++++++++++ plays/lib/prepare.yml | 17 -------- plays/lib/vars.yml | 26 ------------ plays/post_delete.yml | 16 ------- plays/postdelete/lib/database.yml | 7 ++++ plays/postdelete/lib/dirs.yml | 5 +++ plays/postdelete/postdelete.yml | 7 ++++ plays/{ => postdeploy}/lib/http.yml | 0 plays/{ => postdeploy}/lib/https.yml | 0 plays/{ => postdeploy}/lib/proxy.yml | 0 .../postdeploy.yml} | 3 +- plays/{ => predeploy}/lib/database.yml | 0 plays/{ => predeploy}/lib/domain.yml | 0 plays/{ => predeploy}/lib/env.yml | 0 plays/{ => predeploy}/lib/volumes.yml | 0 .../predeploy.yml} | 3 +- 16 files changed, 63 insertions(+), 63 deletions(-) create mode 100644 plays/commonlib/vars.yml delete mode 100644 plays/lib/prepare.yml delete mode 100644 plays/lib/vars.yml delete mode 100644 plays/post_delete.yml create mode 100644 plays/postdelete/lib/database.yml create mode 100644 plays/postdelete/lib/dirs.yml create mode 100644 plays/postdelete/postdelete.yml rename plays/{ => postdeploy}/lib/http.yml (100%) rename plays/{ => postdeploy}/lib/https.yml (100%) rename plays/{ => postdeploy}/lib/proxy.yml (100%) rename plays/{post_deploy.yml => postdeploy/postdeploy.yml} (68%) rename plays/{ => predeploy}/lib/database.yml (100%) rename plays/{ => predeploy}/lib/domain.yml (100%) rename plays/{ => predeploy}/lib/env.yml (100%) rename plays/{ => predeploy}/lib/volumes.yml (100%) rename plays/{pre_deploy.yml => predeploy/predeploy.yml} (73%) diff --git a/plays/commonlib/vars.yml b/plays/commonlib/vars.yml new file mode 100644 index 0000000..517e106 --- /dev/null +++ b/plays/commonlib/vars.yml @@ -0,0 +1,42 @@ +--- +- name: Check if internal system variables exists + stat: + path: "{{ plugin_config_root }}/vars.yml" + register: vars_yml + +- name: Load internal system variables + no_log: true + when: vars_yml.stat.exists + include_vars: + file: "{{ plugin_config_root }}/vars.yml" + +- name: Export internal deployment variables + set_fact: + dokku_mariadb_db_addr: "dokku-mariadb-{{ app }}" + dokku_mariadb_db_user: "mariadb" + dokku_hostname: "{{ lookup('file', '/home/dokku/HOSTNAME') }}" + +- name: Check if the application config file exists + stat: + path: "{{ app_config_root }}/config.yml" + register: config_yml + +- name: Load unencrypted configuration variables + no_log: true + when: config_yml.stat.exists + include_vars: + file: "{{ app_config_root }}/config.yml" + +- name: Check if an application vault directory exists + stat: + path: "{{ app_config_root }}/vault" + register: vault_dir + +- name: Load application encrypted vault variables + no_log: true + when: vault_dir.stat.exists + include_vars: + ignore_unknown_extensions: true + dir: "{{ app_config_root }}/vault" + extensions: + - yml diff --git a/plays/lib/prepare.yml b/plays/lib/prepare.yml deleted file mode 100644 index 9d1913f..0000000 --- a/plays/lib/prepare.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Check if internal system variables exists - stat: - path: "{{ plugin_config_root }}/vars.yml" - register: vars_yml - -- name: Load internal system variables - no_log: true - when: vars_yml.stat.exists - include_vars: - file: "{{ plugin_config_root }}/vars.yml" - -- name: Export internal variable placeholders - set_fact: - dokku_mariadb_db_addr: "dokku-mariadb-{{ app }}" - dokku_mariadb_db_user: "mariadb" - dokku_hostname: "{{ lookup('file', '/home/dokku/HOSTNAME') }}" diff --git a/plays/lib/vars.yml b/plays/lib/vars.yml deleted file mode 100644 index 2c83af8..0000000 --- a/plays/lib/vars.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- name: Check if the app config file exists - stat: - path: "{{ app_config_root }}/config.yml" - register: config_yml - -- name: Load unencrypted variables - no_log: true - when: config_yml.stat.exists - include_vars: - file: "{{ app_config_root }}/config.yml" - -- name: Check if a vault directory exists - stat: - path: "{{ app_config_root }}/vault" - register: vault_dir - -- name: Load encrypted variables - no_log: true - when: vault_dir.stat.exists - include_vars: - ignore_unknown_extensions: true - dir: "{{ app_config_root }}/vault" - extensions: - - yml - - yaml diff --git a/plays/post_delete.yml b/plays/post_delete.yml deleted file mode 100644 index c2993c0..0000000 --- a/plays/post_delete.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- hosts: all - gather_facts: false - tasks: - - include: ./lib/prepare.yml - - include: ./lib/vars.yml - - name: Remove deploy.d folder - file: - path: "{{ app_config_root }}" - state: absent - - name: Remove database(s) - shell: "dokku {{ item.type }}:destroy {{ app }} --force" - args: - removes: "/var/lib/dokku/services/{{ item.type }}/{{ app }}" - with_items: "{{ db }}" - when: db is defined diff --git a/plays/postdelete/lib/database.yml b/plays/postdelete/lib/database.yml new file mode 100644 index 0000000..8a28bcb --- /dev/null +++ b/plays/postdelete/lib/database.yml @@ -0,0 +1,7 @@ +--- +- name: Remove database(s) + shell: "dokku {{ item.type }}:destroy {{ app }} --force" + args: + removes: "/var/lib/dokku/services/{{ item.type }}/{{ app }}" + with_items: "{{ db }}" + when: db is defined diff --git a/plays/postdelete/lib/dirs.yml b/plays/postdelete/lib/dirs.yml new file mode 100644 index 0000000..df529d8 --- /dev/null +++ b/plays/postdelete/lib/dirs.yml @@ -0,0 +1,5 @@ +--- +- name: Remove application deploy.d folder + file: + path: "{{ app_config_root }}" + state: absent diff --git a/plays/postdelete/postdelete.yml b/plays/postdelete/postdelete.yml new file mode 100644 index 0000000..63325e8 --- /dev/null +++ b/plays/postdelete/postdelete.yml @@ -0,0 +1,7 @@ +--- +- hosts: all + gather_facts: false + tasks: + - include: ../commonlib/vars.yml + - include: ./lib/dirs.yml + - include: ./lib/database.yml diff --git a/plays/lib/http.yml b/plays/postdeploy/lib/http.yml similarity index 100% rename from plays/lib/http.yml rename to plays/postdeploy/lib/http.yml diff --git a/plays/lib/https.yml b/plays/postdeploy/lib/https.yml similarity index 100% rename from plays/lib/https.yml rename to plays/postdeploy/lib/https.yml diff --git a/plays/lib/proxy.yml b/plays/postdeploy/lib/proxy.yml similarity index 100% rename from plays/lib/proxy.yml rename to plays/postdeploy/lib/proxy.yml diff --git a/plays/post_deploy.yml b/plays/postdeploy/postdeploy.yml similarity index 68% rename from plays/post_deploy.yml rename to plays/postdeploy/postdeploy.yml index 0322d3a..16b3dc5 100644 --- a/plays/post_deploy.yml +++ b/plays/postdeploy/postdeploy.yml @@ -2,8 +2,7 @@ - hosts: all gather_facts: false tasks: - - include: ./lib/prepare.yml - - include: ./lib/vars.yml + - include: ../commonlib/vars.yml - include: ./lib/http.yml - include: ./lib/https.yml - include: ./lib/proxy.yml diff --git a/plays/lib/database.yml b/plays/predeploy/lib/database.yml similarity index 100% rename from plays/lib/database.yml rename to plays/predeploy/lib/database.yml diff --git a/plays/lib/domain.yml b/plays/predeploy/lib/domain.yml similarity index 100% rename from plays/lib/domain.yml rename to plays/predeploy/lib/domain.yml diff --git a/plays/lib/env.yml b/plays/predeploy/lib/env.yml similarity index 100% rename from plays/lib/env.yml rename to plays/predeploy/lib/env.yml diff --git a/plays/lib/volumes.yml b/plays/predeploy/lib/volumes.yml similarity index 100% rename from plays/lib/volumes.yml rename to plays/predeploy/lib/volumes.yml diff --git a/plays/pre_deploy.yml b/plays/predeploy/predeploy.yml similarity index 73% rename from plays/pre_deploy.yml rename to plays/predeploy/predeploy.yml index ae67d59..25b9106 100644 --- a/plays/pre_deploy.yml +++ b/plays/predeploy/predeploy.yml @@ -2,8 +2,7 @@ - hosts: all gather_facts: false tasks: - - include: ./lib/prepare.yml - - include: ./lib/vars.yml + - include: ../commonlib/vars.yml - include: ./lib/domain.yml - include: ./lib/database.yml - include: ./lib/volumes.yml