tripleo-heat-templates/common
Michele Baldessari ed2b957a4f 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-21 08:06:41 +01:00
..
deploy-steps-tasks.yaml Fix all outputs|failed and outputs is defined 2017-11-21 08:06:41 +01:00
deploy-steps.j2 Revert "Revert "Tag workflows created by the templates"" 2017-11-15 17:24:51 +00:00
major_upgrade_steps.j2.yaml Merge "Adds post_upgrade_tasks for any service post-upgrade ansible tasks" 2017-09-20 11:16:26 +00:00
post-upgrade.j2.yaml Add RoleConfig output to major_upgrade_steps.j2.yaml 2017-09-12 09:58:50 +01:00
post.j2.yaml Consolidate puppet/docker deployments with one deploy steps workflow 2017-08-11 17:25:02 +00:00
services.yaml Refactor cellv2 host discovery logic to avoid races 2017-11-08 23:20:46 +00:00