From 22e15e4b50b131ad20b84d77176ef79266836dc9 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Tue, 14 Apr 2020 13:02:16 +0200 Subject: [PATCH] Adapt to more scoped config --- plays/commonlib/vars.yml | 16 +++++++++++++--- plays/postdelete/lib/database.yml | 4 ++-- plays/postdeploy/lib/http.yml | 4 ++-- plays/postdeploy/lib/https.yml | 10 +++++----- plays/postdeploy/lib/nginxd.yml | 12 ++++++++++-- plays/postdeploy/lib/proxy.yml | 4 ++-- plays/predeploy/lib/database.yml | 12 ++++++------ plays/predeploy/lib/domain.yml | 8 ++++---- plays/predeploy/lib/env.yml | 2 +- plays/predeploy/lib/templates.yml | 9 +++++++++ plays/predeploy/predeploy.yml | 1 + 11 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 plays/predeploy/lib/templates.yml diff --git a/plays/commonlib/vars.yml b/plays/commonlib/vars.yml index 517e106..9f3f23a 100644 --- a/plays/commonlib/vars.yml +++ b/plays/commonlib/vars.yml @@ -1,4 +1,8 @@ --- +# Note(decentral1se): please note that the majority of the vars that are +# referenced in this play are passed in via --extra-vars definitions in the +# functions script + - name: Check if internal system variables exists stat: path: "{{ plugin_config_root }}/vars.yml" @@ -12,9 +16,13 @@ - 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') }}" + dokku: + { + app: "{{ app }}", + mariadb_addr: "dokku-mariadb-{{ app }}", + mariadb_user: "mariadb", + hostname: "{{ lookup('file', '/home/dokku/HOSTNAME') }}", + } - name: Check if the application config file exists stat: @@ -26,6 +34,7 @@ when: config_yml.stat.exists include_vars: file: "{{ app_config_root }}/config.yml" + name: "config" - name: Check if an application vault directory exists stat: @@ -38,5 +47,6 @@ include_vars: ignore_unknown_extensions: true dir: "{{ app_config_root }}/vault" + name: "vault" extensions: - yml diff --git a/plays/postdelete/lib/database.yml b/plays/postdelete/lib/database.yml index 8a28bcb..c2f7eff 100644 --- a/plays/postdelete/lib/database.yml +++ b/plays/postdelete/lib/database.yml @@ -1,7 +1,7 @@ --- - name: Remove database(s) - shell: "dokku {{ item.type }}:destroy {{ app }} --force" + shell: "dokku {{ item.type }}:destroy {{ dokku.app }} --force" args: - removes: "/var/lib/dokku/services/{{ item.type }}/{{ app }}" + removes: "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}" with_items: "{{ db }}" when: db is defined diff --git a/plays/postdeploy/lib/http.yml b/plays/postdeploy/lib/http.yml index 5447b9b..c084fb9 100644 --- a/plays/postdeploy/lib/http.yml +++ b/plays/postdeploy/lib/http.yml @@ -1,7 +1,7 @@ --- - name: Set HTTP 80 port proxy dokku_ports: - app: "{{ app }}" + app: "{{ dokku.app }}" mappings: - - "http:80:{{ port }}" + - "http:80:{{ vars.port }}" state: present diff --git a/plays/postdeploy/lib/https.yml b/plays/postdeploy/lib/https.yml index f7a45c8..ad6a9d4 100644 --- a/plays/postdeploy/lib/https.yml +++ b/plays/postdeploy/lib/https.yml @@ -1,17 +1,17 @@ --- - name: Setup lets encrypt certificates - shell: "dokku letsencrypt {{ app }}" + shell: "dokku letsencrypt {{ dokku.app }}" args: - creates: "/home/dokku/{{ app }}/letsencrypt/certs" + creates: "/home/dokku/{{ dokku.app }}/letsencrypt/certs" - name: Setup lets encrypt certificates renew cron job shell: dokku letsencrypt:cron-job --add args: - creates: "/home/dokku/{{ app }}/letsencrypt/cron-job" + creates: "/home/dokku/{{ dokku.app }}/letsencrypt/cron-job" - name: Set HTTP 443 port dokku_ports: - app: "{{ app }}" + app: "{{ dokku.app }}" mappings: - - "https:443:{{ port }}" + - "https:443:{{ vars.port }}" state: present diff --git a/plays/postdeploy/lib/nginxd.yml b/plays/postdeploy/lib/nginxd.yml index 8583d95..9a211e1 100644 --- a/plays/postdeploy/lib/nginxd.yml +++ b/plays/postdeploy/lib/nginxd.yml @@ -1,24 +1,32 @@ --- +- name: Check if a custom nginx directory exists + stat: + path: "{{ app_config_root }}/nginx.d/" + register: custom_nginx_d + - name: Create nginx customisation directory become: true file: - path: "/home/dokku/{{ app }}/nginx.conf.d/" + path: "/home/dokku/{{ dokku.app }}/nginx.conf.d/" state: directory owner: dokku group: dokku + when: custom_nginx_d.stat.exists - name: Copy over the nginx custom configuration become: true template: src: "{{ item }}" - dest: "/home/dokku/{{ app }}/nginx.conf.d/{{ item | basename }}" + dest: "/home/dokku/{{ dokku.app }}/nginx.conf.d/{{ item | basename }}" owner: dokku group: dokku with_fileglob: - "{{ app_config_root }}/nginx.d/*.conf" + when: custom_nginx_d.stat.exists - name: Reload nginx to enable custom configurations become: true service: name: nginx state: reloaded + when: custom_nginx_d.stat.exists diff --git a/plays/postdeploy/lib/proxy.yml b/plays/postdeploy/lib/proxy.yml index 44d7d6d..aea54f2 100644 --- a/plays/postdeploy/lib/proxy.yml +++ b/plays/postdeploy/lib/proxy.yml @@ -1,7 +1,7 @@ --- - name: Remove automatically configured ports dokku_ports: - app: "{{ app }}" + app: "{{ dokku.app }}" mappings: - - "http:{{ port }}:{{ port }}" + - "http:{{ vars.port }}:{{ vars.port }}" state: absent diff --git a/plays/predeploy/lib/database.yml b/plays/predeploy/lib/database.yml index fdb285f..524d9de 100644 --- a/plays/predeploy/lib/database.yml +++ b/plays/predeploy/lib/database.yml @@ -10,27 +10,27 @@ shell: " dokku {{ item.type }}:create - {{ app }} + {{ dokku.app }} --password {{ item.passwd }} --root-password {{ item.root_passwd }} " args: - creates: "/var/lib/dokku/services/{{ item.type }}/{{ app }}" + creates: "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}" with_items: "{{ db }}" when: db is defined - name: "Link {{ item.type }} database to application" dokku_service_link: - app: "{{ app }}" - name: "{{ app }}" + app: "{{ dokku.app }}" + name: "{{ dokku.app }}" service: "{{ item.type }}" with_items: "{{ db }}" when: db is defined - name: "Specify {{ item.type }} volume mounts" dokku_storage: - app: "{{ app }}" + app: "{{ dokku.app }}" mounts: - - "/var/lib/dokku/services/{{ item.type }}/{{ app }}:{{ mount_map[item.type] }}" + - "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}:{{ mount_map[item.type] }}" with_items: "{{ db }}" when: db is defined diff --git a/plays/predeploy/lib/domain.yml b/plays/predeploy/lib/domain.yml index 120067e..45fe974 100644 --- a/plays/predeploy/lib/domain.yml +++ b/plays/predeploy/lib/domain.yml @@ -1,8 +1,8 @@ --- -- name: "Configure {{ domain }} dedicated domain" +- name: "Configure {{ vars.domain }} dedicated domain" dokku_domains: - app: "{{ app }}" + app: "{{ dokku.app }}" domains: - - "{{ domain }}" + - "{{ vars.domain }}" state: present - when: domain is defined + when: vars.domain is defined diff --git a/plays/predeploy/lib/env.yml b/plays/predeploy/lib/env.yml index 57f046b..c3dcebc 100644 --- a/plays/predeploy/lib/env.yml +++ b/plays/predeploy/lib/env.yml @@ -1,7 +1,7 @@ --- - name: Configure the app environment dokku_config: - app: "{{ app }}" + app: "{{ dokku.app }}" restart: false config: "{{ env }}" when: env is defined diff --git a/plays/predeploy/lib/templates.yml b/plays/predeploy/lib/templates.yml new file mode 100644 index 0000000..b4dbd6c --- /dev/null +++ b/plays/predeploy/lib/templates.yml @@ -0,0 +1,9 @@ +--- +- name: Copy over template files + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: dokku + group: dokku + with_items: "{{ templates }}" + when: templates is defined diff --git a/plays/predeploy/predeploy.yml b/plays/predeploy/predeploy.yml index 8b4e27e..c59953e 100644 --- a/plays/predeploy/predeploy.yml +++ b/plays/predeploy/predeploy.yml @@ -6,5 +6,6 @@ - include: ./lib/domain.yml - include: ./lib/database.yml - include: ./lib/volumes.yml + - include: ./lib/templates.yml - include: ./lib/env.yml - include: ./lib/hooks.yml