Do not fail on non existent ansible group

When a role is defined but this role has a host count of 0, the ansible
tasks to generate the openshift inventory for the service would fail
with an undefined variable error.

Setting the value for non existent groups to empty array should get us
past the error.

Change-Id: Ib42708c095d28827f5decdb885ceb4f2a67b3a8b
This commit is contained in:
Martin André 2018-06-11 11:23:55 +02:00
parent b95d1c18d8
commit cc046a757c
2 changed files with 2 additions and 2 deletions

View File

@ -97,7 +97,7 @@ outputs:
template: |
masters:
hosts:
{% for host in groups['ROLENAME'] -%}
{% for host in groups['ROLENAME'] | default([]) -%}
{{ hostvars.raw_get(host)['ansible_hostname'] }}:
ansible_user: {{ hostvars.raw_get(host)['ansible_user'] | default(hostvars.raw_get(host)['ansible_ssh_user']) | default('root') }}
ansible_host: {{ hostvars.raw_get(host)['ansible_host'] | default(host) }}

View File

@ -77,7 +77,7 @@ outputs:
template: |
nodes:
hosts:
{% for host in groups['ROLENAME'] -%}
{% for host in groups['ROLENAME'] | default([]) -%}
{{ hostvars.raw_get(host)['ansible_hostname'] }}:
ansible_user: {{ hostvars.raw_get(host)['ansible_user'] | default(hostvars.raw_get(host)['ansible_ssh_user']) | default('root') }}
ansible_host: {{ hostvars.raw_get(host)['ansible_host'] | default(host) }}