Move to dictionary vars strategy

This commit is contained in:
Luke Murphy 2020-04-14 13:44:09 +02:00
parent 618ae495b2
commit 5e9cc84e8b
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
10 changed files with 43 additions and 41 deletions

View File

@ -14,16 +14,6 @@
include_vars:
file: "{{ plugin_config_root }}/vars.yml"
- name: Export internal deployment variables
set_fact:
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:
path: "{{ app_config_root }}/config.yml"
@ -35,10 +25,6 @@
include_vars:
file: "{{ app_config_root }}/config.yml"
- name: CONFIG DEBUG
debug:
msg: "{{ vars }}"
- name: Check if an application vault directory exists
stat:
path: "{{ app_config_root }}/vault"
@ -50,11 +36,25 @@
include_vars:
ignore_unknown_extensions: true
dir: "{{ app_config_root }}/vault"
name: "vault"
extensions:
- yml
register: vault_include
- name: Load vault variables into vault dictionary
- name: Create the variable dictionaries
set_fact:
vault: "{{ vault_include.ansible_facts.vault }}"
config:
{
"vars": "{{ lookup('vars', 'vars.vars', default=[]) }}",
"db": "{{ lookup('vars', 'vars.db', default=[]) }}",
"env": "{{ lookup('vars', 'vars.env', default=[]) }}",
"volumes": "{{ lookup('vars', 'vars.volumes', default=[]) }}",
"templates": "{{ lookup('vars', 'vars.templates', default=[]) }}",
"vault": "{{ vault_include.ansible_facts.vault }}",
}
dokku:
{
app: "{{ app }}",
mariadb_addr: "dokku-mariadb-{{ app }}",
mariadb_user: "mariadb",
hostname: "{{ lookup('file', '/home/dokku/HOSTNAME') }}",
}

View File

@ -4,5 +4,5 @@
shell: "dokku {{ item.type }}:destroy {{ dokku.app }} --force"
args:
removes: "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}"
with_items: "{{ db }}"
when: db is defined
with_items: "{{ config.db }}"
when: config.db

View File

@ -3,5 +3,5 @@
dokku_ports:
app: "{{ dokku.app }}"
mappings:
- "http:80:{{ vars.port }}"
- "http:80:{{ config.vars.port }}"
state: present

View File

@ -13,5 +13,5 @@
dokku_ports:
app: "{{ dokku.app }}"
mappings:
- "https:443:{{ vars.port }}"
- "https:443:{{ config.vars.port }}"
state: present

View File

@ -3,5 +3,5 @@
dokku_ports:
app: "{{ dokku.app }}"
mappings:
- "http:{{ vars.port }}:{{ vars.port }}"
- "http:{{ config.vars.port }}:{{ config.vars.port }}"
state: absent

View File

@ -1,9 +1,10 @@
---
- name: Set database facts
no_log: true
set_fact:
mount_map:
mariadb: /var/lib/mysql
when: db is defined
when: config.db
- name: "Create {{ item.type }} database"
no_log: true
@ -16,8 +17,8 @@
"
args:
creates: "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}"
with_items: "{{ db }}"
when: db is defined
with_items: "{{ config.db }}"
when: config.db
- name: "Link {{ item.type }} database to application"
no_log: true
@ -25,13 +26,14 @@
app: "{{ dokku.app }}"
name: "{{ dokku.app }}"
service: "{{ item.type }}"
with_items: "{{ db }}"
when: db is defined
with_items: "{{ config.db }}"
when: config.db
- name: "Specify {{ item.type }} volume mounts"
no_log: true
dokku_storage:
app: "{{ dokku.app }}"
mounts:
- "/var/lib/dokku/services/{{ item.type }}/{{ dokku.app }}:{{ mount_map[item.type] }}"
with_items: "{{ db }}"
when: db is defined
with_items: "{{ config.db }}"
when: config.db

View File

@ -1,8 +1,8 @@
---
- name: "Configure {{ vars.domain }} dedicated domain"
- name: "Configure {{ config.vars.domain }} dedicated domain"
dokku_domains:
app: "{{ dokku.app }}"
domains:
- "{{ vars.domain }}"
- "{{ config.vars.domain }}"
state: present
when: vars.domain is defined
when: "'domain' in config.vars"

View File

@ -3,5 +3,5 @@
dokku_config:
app: "{{ dokku.app }}"
restart: false
config: "{{ env }}"
when: env is defined
config: "{{ config.env }}"
when: config.env

View File

@ -5,5 +5,5 @@
dest: "{{ item.dest }}"
owner: dokku
group: dokku
with_items: "{{ templates }}"
when: templates is defined
with_items: "{{ config.templates }}"
when: config.templates

View File

@ -6,12 +6,12 @@
state: directory
owner: dokku
group: dokku
with_items: "{{ mounts }}"
when: mounts is defined
with_items: "{{ config.volumes }}"
when: config.volumes
- name: Attach volume mounts
dokku_storage:
app: "{{ app }}"
app: "{{ dokku.app }}"
mounts: "{{ item }}"
with_items: "{{ mounts }}"
when: mounts is defined
with_items: "{{ config.volumes }}"
when: config.volumes