tripleo-heat-templates/common/deploy-steps-tasks.yaml

100 lines
4.3 KiB
YAML
Raw Normal View History

# Note the indentation here is required as it's joined
# to create a playbook in deploy-steps.j2
#####################################################
# Per step puppet configuration of the baremetal host
#####################################################
- name: Set host puppet debugging fact string
set_fact:
host_puppet_config_debug: "--debug --verbose"
when: enable_debug|default(false)
- name: Write the config_step hieradata
copy: content="{{dict(step=step|int)|to_json}}" dest=/etc/puppet/hieradata/config_step.json force=true mode=0600
become: true
- name: Run puppet host configuration for step {{step}}
command: >-
puppet apply {{ host_puppet_config_debug|default('') }}
--modulepath=/etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules
--detailed-exitcodes
--logdest syslog --logdest console --color=false
/var/lib/tripleo-config/puppet_step_config.pp
changed_when: outputs.rc == 2
check_mode: no
register: outputs
failed_when: false
no_log: true
become: true
- debug: var=outputs.stdout_lines|default([])|union(outputs.stderr_lines|default([]))
Fix all outputs|failed and outputs is defined The ansible "failed_when" filter that uses a registered output of a previous task piped to the '|failed' filter does not work as expected. Given the following playbook: - name: return code shell: | echo "fail 2" exit 2 failed_when: false log_when: false register: outputs - debug: msg: "rc: {{ outputs.rc }}" - debug: msg="Broken (does not fail as expected)" when: outputs is defined failed_when: outputs|failed - debug: msg="Working (fails as expected)" when: outputs is defined failed_when: outputs.rc != 0 We obtain the following output: TASK [return code] **** changed: [localhost] TASK [debug] ********** ok: [localhost] => { "msg": "rc: 2" } TASK [debug] ********** ok: [localhost] => { "failed_when_result": false, "msg": "Broken (does not fail as expected)" } TASK [debug] ********** fatal: [localhost]: FAILED! => { "failed_when_result": true, "msg": "Working (fails as expected)" } This means that the 'outputs|failed' just does not work at all. Let's move to a more explicit check on the rc code of the registered variable. We also need to fix all the "outputs is defined" checks, because when a task is skipped the registered outputs variable *is* actually defined as the following dictionary: {'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False} So we use "outputs.rc is defined" in order to make sure that the previous task did indeed run. Closes-Bug: #1733402 Change-Id: I6ef53dc3f9aede42f10c7f110d24722355481261
2017-11-20 20:48:50 +01:00
when: outputs.rc is defined
failed_when: outputs.rc not in [0, 2]
######################################
# Generate config via docker-puppet.py
######################################
- name: Run docker-puppet tasks (generate config)
shell: python /var/lib/docker-puppet/docker-puppet.py
environment:
NET_HOST: 'true'
DEBUG: '{{docker_puppet_debug|default(false)}}'
PROCESS_COUNT: '{{docker_puppet_process_count|default(3)}}'
when: step == "1"
changed_when: false
check_mode: no
register: outputs
failed_when: false
no_log: true
become: true
- debug: var=outputs.stdout_lines|default([])|union(outputs.stderr_lines|default([]))
Fix all outputs|failed and outputs is defined The ansible "failed_when" filter that uses a registered output of a previous task piped to the '|failed' filter does not work as expected. Given the following playbook: - name: return code shell: | echo "fail 2" exit 2 failed_when: false log_when: false register: outputs - debug: msg: "rc: {{ outputs.rc }}" - debug: msg="Broken (does not fail as expected)" when: outputs is defined failed_when: outputs|failed - debug: msg="Working (fails as expected)" when: outputs is defined failed_when: outputs.rc != 0 We obtain the following output: TASK [return code] **** changed: [localhost] TASK [debug] ********** ok: [localhost] => { "msg": "rc: 2" } TASK [debug] ********** ok: [localhost] => { "failed_when_result": false, "msg": "Broken (does not fail as expected)" } TASK [debug] ********** fatal: [localhost]: FAILED! => { "failed_when_result": true, "msg": "Working (fails as expected)" } This means that the 'outputs|failed' just does not work at all. Let's move to a more explicit check on the rc code of the registered variable. We also need to fix all the "outputs is defined" checks, because when a task is skipped the registered outputs variable *is* actually defined as the following dictionary: {'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False} So we use "outputs.rc is defined" in order to make sure that the previous task did indeed run. Closes-Bug: #1733402 Change-Id: I6ef53dc3f9aede42f10c7f110d24722355481261
2017-11-20 20:48:50 +01:00
when: outputs.rc is defined
failed_when: outputs.rc != 0
##################################################
# Per step starting of the containers using paunch
##################################################
- name: Check if /var/lib/hashed-tripleo-config/docker-container-startup-config-step_{{step}}.json exists
stat:
path: /var/lib/tripleo-config/hashed-docker-container-startup-config-step_{{step}}.json
register: docker_config_json
become: true
# Note docker-puppet.py generates the hashed-*.json file, which is a copy of
# the *step_n.json with a hash of the generated external config added
# This acts as a salt to enable restarting the container if config changes
- name: Start containers for step {{step}}
command: >-
paunch --debug apply
--file /var/lib/tripleo-config/hashed-docker-container-startup-config-step_{{step}}.json
--config-id tripleo_step{{step}} --managed-by tripleo-{{role_name}}
when: docker_config_json.stat.exists
changed_when: false
check_mode: no
register: outputs
failed_when: false
no_log: true
become: true
- debug: var=outputs.stdout_lines|default([])|union(outputs.stderr_lines|default([]))
Fix all outputs|failed and outputs is defined The ansible "failed_when" filter that uses a registered output of a previous task piped to the '|failed' filter does not work as expected. Given the following playbook: - name: return code shell: | echo "fail 2" exit 2 failed_when: false log_when: false register: outputs - debug: msg: "rc: {{ outputs.rc }}" - debug: msg="Broken (does not fail as expected)" when: outputs is defined failed_when: outputs|failed - debug: msg="Working (fails as expected)" when: outputs is defined failed_when: outputs.rc != 0 We obtain the following output: TASK [return code] **** changed: [localhost] TASK [debug] ********** ok: [localhost] => { "msg": "rc: 2" } TASK [debug] ********** ok: [localhost] => { "failed_when_result": false, "msg": "Broken (does not fail as expected)" } TASK [debug] ********** fatal: [localhost]: FAILED! => { "failed_when_result": true, "msg": "Working (fails as expected)" } This means that the 'outputs|failed' just does not work at all. Let's move to a more explicit check on the rc code of the registered variable. We also need to fix all the "outputs is defined" checks, because when a task is skipped the registered outputs variable *is* actually defined as the following dictionary: {'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False} So we use "outputs.rc is defined" in order to make sure that the previous task did indeed run. Closes-Bug: #1733402 Change-Id: I6ef53dc3f9aede42f10c7f110d24722355481261
2017-11-20 20:48:50 +01:00
when: outputs.rc is defined
failed_when: outputs.rc != 0
########################################################
# Bootstrap tasks, only performed on bootstrap_server_id
########################################################
- name: Check if /var/lib/docker-puppet/docker-puppet-tasks{{step}}.json exists
stat:
path: /var/lib/docker-puppet/docker-puppet-tasks{{step}}.json
register: docker_puppet_tasks_json
become: true
- name: Run docker-puppet tasks (bootstrap tasks)
shell: python /var/lib/docker-puppet/docker-puppet.py
environment:
CONFIG: /var/lib/docker-puppet/docker-puppet-tasks{{step}}.json
NET_HOST: "true"
NO_ARCHIVE: "true"
STEP: "{{step}}"
when: deploy_server_id == bootstrap_server_id and docker_puppet_tasks_json.stat.exists
changed_when: false
check_mode: no
register: outputs
failed_when: false
no_log: true
become: true
- debug: var=outputs.stdout_lines|default([])|union(outputs.stderr_lines|default([]))
Fix all outputs|failed and outputs is defined The ansible "failed_when" filter that uses a registered output of a previous task piped to the '|failed' filter does not work as expected. Given the following playbook: - name: return code shell: | echo "fail 2" exit 2 failed_when: false log_when: false register: outputs - debug: msg: "rc: {{ outputs.rc }}" - debug: msg="Broken (does not fail as expected)" when: outputs is defined failed_when: outputs|failed - debug: msg="Working (fails as expected)" when: outputs is defined failed_when: outputs.rc != 0 We obtain the following output: TASK [return code] **** changed: [localhost] TASK [debug] ********** ok: [localhost] => { "msg": "rc: 2" } TASK [debug] ********** ok: [localhost] => { "failed_when_result": false, "msg": "Broken (does not fail as expected)" } TASK [debug] ********** fatal: [localhost]: FAILED! => { "failed_when_result": true, "msg": "Working (fails as expected)" } This means that the 'outputs|failed' just does not work at all. Let's move to a more explicit check on the rc code of the registered variable. We also need to fix all the "outputs is defined" checks, because when a task is skipped the registered outputs variable *is* actually defined as the following dictionary: {'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False} So we use "outputs.rc is defined" in order to make sure that the previous task did indeed run. Closes-Bug: #1733402 Change-Id: I6ef53dc3f9aede42f10c7f110d24722355481261
2017-11-20 20:48:50 +01:00
when: outputs.rc is defined
failed_when: outputs.rc != 0