You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.7 KiB
68 lines
2.7 KiB
- hosts: all
|
|
gather_facts: no
|
|
serial: "{{ hosts_per_batch | d(1) | int }}"
|
|
strategy: "{{ hosts_strategy | d('linear') }}"
|
|
tasks:
|
|
- name: get primary role
|
|
set_fact:
|
|
host_primary_role: "{%- if primary_role is defined -%}{{ primary_role }}\
|
|
{%- elif hostvars[inventory_hostname]['primary_role'] is defined -%}{{ hostvars[inventory_hostname]['primary_role'] }}\
|
|
{%- else -%}{{ inventory_hostname }}\
|
|
{%- endif -%}"
|
|
|
|
|
|
- name: import role mappings
|
|
import_tasks: mappings.yml
|
|
|
|
|
|
- name: fail if mappings are missing
|
|
fail:
|
|
msg: role mappings are missing or invalid
|
|
when: (common_roles is not defined) or (common_roles | type_debug != 'list')
|
|
|
|
|
|
- name: warn if current role mapping is missing
|
|
debug:
|
|
msg: "mapping for role \"{{ host_primary_role }}\" is missing - using default role mapping at stage 6"
|
|
when: (extra_roles | d({}))[host_primary_role] is not defined
|
|
|
|
|
|
- name: build role mapping
|
|
set_fact:
|
|
role_mapping: "{{ (((extra_roles | d({}))[host_primary_role] | d([{ 'stage': 6, 'role': host_primary_role }])) +
|
|
([] if host_primary_role in (no_common_roles | d([])) else common_roles) +
|
|
([{ 'stage': 1, 'role': 'container' }] if 'containers' in group_names else []) +
|
|
([{ 'stage': 3, 'role': 'postgres', 'function': 'integrate' }] if host_primary_role in (database_roles | d([])) else [])
|
|
) | sort(attribute='stage') }}"
|
|
|
|
|
|
- name: remember selected stages
|
|
set_fact:
|
|
selected_stages: "{%- if stage is defined and ((stage | string) is search(',')) -%}{{ stage | string | split(',') | list | map('int') | list }}\
|
|
{%- elif (stage is not defined) or ((stage | int) == 0) -%}{{ [1,2,3,4,5,6,7,8,9] }}\
|
|
{%- else -%}{{ [stage | int] }}\
|
|
{%- endif -%}"
|
|
no_log: yes
|
|
|
|
|
|
- name: show deployment info
|
|
debug:
|
|
msg: "deploying primary role \"{{ host_primary_role }}\" on host \"{{ inventory_hostname }}\", {{
|
|
(('stages ' if (selected_stages | length > 1) else 'stage ') ~ (selected_stages | join(', ')))
|
|
if ([1,2,3,4,5,6,7,8,9] | symmetric_difference(selected_stages) | list | length > 0) else 'all stages' }}"
|
|
|
|
|
|
- name: run pre_tasks
|
|
include_tasks: tasks/pre_tasks.yml
|
|
|
|
|
|
- name: run stages
|
|
include_tasks: tasks/includes/stage.yml
|
|
loop: "{{ selected_stages }}"
|
|
loop_control:
|
|
loop_var: this_stage
|
|
|
|
|
|
- name: show deployment info
|
|
debug:
|
|
msg: "ok: deployment completed on host \"{{ inventory_hostname }}\""
|
|
|