|
|
|
- hosts: all
|
|
|
|
gather_facts: no
|
|
|
|
serial: "{{ hosts_per_batch | d(1) | int }}"
|
|
|
|
strategy: "{{ hosts_strategy | d('linear') }}"
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
# TODO: multiple roles
|
|
|
|
- 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: check if role info file exists
|
|
|
|
stat:
|
|
|
|
path: "{{ (playbook_dir, 'roles', host_primary_role, 'tasks', 'info.yml') | path_join }}"
|
|
|
|
delegate_to: localhost
|
|
|
|
register: result
|
|
|
|
no_log: yes
|
|
|
|
|
|
|
|
|
|
|
|
- name: get role info
|
|
|
|
include_role:
|
|
|
|
name: "{{ host_primary_role }}"
|
|
|
|
tasks_from: info.yml
|
|
|
|
apply:
|
|
|
|
no_log: yes
|
|
|
|
when: result.stat.exists
|
|
|
|
|
|
|
|
|
|
|
|
- name: build role dependency list and stage info
|
|
|
|
set_fact:
|
|
|
|
role_deps: "{{ (([{ 'stage': 6, 'role': host_primary_role }] if role_dependency is not defined else [role_dependency]) +
|
|
|
|
([role_dependency_common] if (role_dependency_no_common | d(false) == false) else []) +
|
|
|
|
([{ 'stage': 1, 'role': 'container' }] if 'containers' in group_names else []) +
|
|
|
|
([{ 'stage': 3, 'role': 'postgres', 'tasks_from': 'integrate.yml' }] if role_use_database | d(false) == true else [])
|
|
|
|
) | flatten(levels=1) | sort(attribute='stage') }}"
|
|
|
|
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 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' }}\n\n{{
|
|
|
|
'dependencies:\n' ~ (role_deps | map(attribute='stage') | list | zip(
|
|
|
|
role_deps | map(attribute='role') | list
|
|
|
|
) | map('join', ': ') | list | join('\n'))
|
|
|
|
}}"
|
|
|
|
|
|
|
|
|
|
|
|
- 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 }}\""
|