tripleo-common/tripleo_common/templates/deployments.yaml

229 lines
8.4 KiB
YAML

- name: Quote the JSON queries to escape invalid characters
set_fact:
item_id: '"{{ item }}".id'
item_group: '"{{ item }}".group'
item_only: '"{{ item }}"'
- name: Lookup deployment UUID
set_fact:
deployment_uuid: "{{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item_id) }}"
- name: Lookup deployment group
set_fact:
deployment_group: "{{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item_group) }}"
- name: Hiera check and diff mode
block:
- name: Create hiera check-mode directory
file:
path: /etc/puppet/check-mode/hieradata
state: directory
check_mode: no
- name: Create deployed check-mode directory
file:
path: /var/lib/heat-config/check-mode
state: directory
check_mode: no
- name: Create tripleo-config-download check-mode directory
file:
path: /var/lib/heat-config/tripleo-config-download/check-mode
state: directory
check_mode: no
- name: "Template deployment file for {{ item }}"
template:
src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
# variable_start/end are overridden since the Heat template must be
# valid yaml, so the jinja expression must be wrapped in quotes in the
# Heat templates. Now, the extra quotes must be removed so that they do
# not end up in the final rendered value. Also, $$ is used as the delimiter
# for the jinja expression since { and } are reserved in yaml.
variable_start_string: "\"$$"
variable_end_string: "$$\""
- name: "Slurp remote deployment file for {{ item }}"
slurp:
src: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
register: deployment_content
- name: "Remote copy deployment file for {{ item }}"
copy:
content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item_only) }} ]"
dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
- name: Run hiera deployment for check mode
shell: |
rm -f /var/lib/heat-config/check-mode/{{ deployment_uuid }}.json
/usr/libexec/os-refresh-config/configure.d/55-heat-config
exit $(jq .deploy_status_code /var/lib/heat-config/check-mode/{{ deployment_uuid }}.notify.json)
args:
warn: false
become: true
environment:
HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/check-mode/{{ item ~ '-' ~ deployment_uuid }}
HEAT_PUPPET_HIERA_DATADIR: /etc/puppet/check-mode/hieradata
HEAT_HIERA_CONFIG: /etc/puppet/check-mode/hiera.yaml
HEAT_CONFIG_DEPLOYED: /var/lib/heat-config/check-mode
check_mode: no
ignore_errors: yes
- name: List hieradata files for check mode
find:
path: /etc/puppet/check-mode/hieradata
register: hieradata_files
check_mode: no
- name: diff hieradata changes for check mode
command:
diff -uN {{ hieradata_item.path | regex_replace('check-mode', '') }} {{ hieradata_item.path }}
with_items: "{{ hieradata_files.files }}"
check_mode: no
register: diff_results
changed_when: diff_results.rc == 1
loop_control:
loop_var: hieradata_item
label: "{{ hieradata_item.path }}"
failed_when: false
when: ansible_diff_mode|bool
- name: diff hieradata changes for check mode
debug:
var: item.stdout_lines
with_items: "{{ diff_results.results }}"
changed_when: item.rc == 1
loop_control:
label: "{{ item._ansible_item_label }}"
when: ansible_diff_mode|bool
- name: hiera.yaml changes for check mode
command:
diff -uN /etc/puppet/hiera.yaml /etc/puppet/check-mode/hiera.yaml
check_mode: no
register: diff_results
changed_when: diff_results.rc == 1
failed_when: false
- name: diff hiera.yaml changes for check mode
debug:
var: diff_results.stdout_lines
changed_when: diff_results.rc == 1
when: ansible_diff_mode|bool
ignore_errors: yes
when:
- deployment_group == 'hiera'
- ansible_check_mode|bool
- name: "Template deployment file for {{ item }}"
template:
src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
# variable_start/end are overridden since the Heat template must be
# valid yaml, so the jinja expression must be wrapped in quotes in the
# Heat templates. Now, the extra quotes must be removed so that they do
# not end up in the final rendered value. Also, $$ is used as the delimiter
# for the jinja expression since { and } are reserved in yaml.
variable_start_string: "\"$$"
variable_end_string: "$$\""
- name: "Slurp remote deployment file for {{ item }}"
slurp:
src: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
register: deployment_content
- name: "Remote copy deployment file for {{ item }}"
copy:
content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item_only) }} ]"
dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
- name: "Check if deployed file exists for {{ item }}"
stat:
path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
register: deployed_file_stat
- name: "Check previous deployment rc for {{ item }}"
shell: |
exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
register: previous_deployment_result
ignore_errors: true
failed_when: false
when: deployed_file_stat.stat.exists
- name: "Remove deployed file for {{ item }} when previous deployment failed"
file:
path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
state: absent
become: true
when:
- not ansible_check_mode|bool
- deployed_file_stat.stat.exists
- previous_deployment_result.rc != 0
- name: "Force remove deployed file for {{ item }}"
file:
path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
state: absent
become: true
when: (force | bool)
- name: Set fact for async_deployment
set_fact:
use_async_deployment: "{{ (async_deployment | default(False)) or (item == 'NetworkDeployment') }}"
- name: "Run deployment {{ item }}"
shell: |
/usr/libexec/os-refresh-config/configure.d/55-heat-config
exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
become: true
environment:
HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}
register: deployment_sync_result
ignore_errors: yes
when: not use_async_deployment|bool
- name: "Run async deployment {{ item }}"
shell: |
/usr/libexec/os-refresh-config/configure.d/55-heat-config
exit $(jq .deploy_status_code /var/lib/heat-config/deployed/{{ deployment_uuid }}.notify.json)
become: true
environment:
HEAT_SHELL_CONFIG: /var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}
register: deployment_async_result
ignore_errors: yes
when: use_async_deployment|bool
async: "{{ async_timeout | default(300) }}"
poll: "{{ async_poll | default(3) }}"
- name: "Output for sync deployment {{ item }}"
debug:
msg:
- stderr: "{{ deployment_sync_result.stderr.split('\n') }}"
- status_code: "{{ deployment_sync_result.rc }}"
tags:
- output
failed_when: deployment_sync_result.rc != 0
when: not ansible_check_mode|bool and not use_async_deployment|bool
- name: "Output for async deployment {{ item }}"
debug:
msg:
- stderr: "{{ deployment_async_result.stderr.split('\n') }}"
- status_code: "{{ deployment_async_result.rc }}"
tags:
- output
failed_when: deployment_async_result.rc != 0
when: not ansible_check_mode|bool and use_async_deployment|bool
- name: "Check-mode for Run deployment {{ item }} (changed status indicates deployment would run)"
stat:
path: /var/lib/heat-config/deployed/{{ deployment_uuid }}.json
become: true
register: deploy_exists
changed_when: not deploy_exists.stat.exists
when: ansible_check_mode|bool
ignore_errors: yes