Rework how we push the content in the file

Since we allow to pass lists, we can't just use |join('').

In addition, using the multi-line support in YAML via the "|" creates
some issues when we want to use |join('\n'): it gets escaped, meaning we
end with a one-line content with some \n entries.

The present patch ensures that:
- generated content is still pushed in a fact to not lose time
- static content (lists) is properly treated and outputs correctly

Change-Id: I7e520035f24503e59840b34e5b2d9e9966cd6ca4
This commit is contained in:
Cédric Jeanneret 2020-03-20 08:22:11 +01:00
parent a70139e5b9
commit 75ed35c46a
1 changed files with 8 additions and 9 deletions

View File

@ -31,10 +31,6 @@
run_once: true
set_fact:
tripleo_hosts_entries_block: |
{{ tripleo_hosts_entries_undercloud_hosts_entries | default([]) | join('') }}
{{ tripleo_hosts_entries_vip_hosts_entries | default([]) | join('') }}
{% for host in groups['overcloud'] -%}
{{ hostvars[host][hostvars[host]['hostname_resolve_network'] ~ '_ip'] ~ ' ' ~
host ~ '.' ~ cloud_domain ~ ' ' ~ host }}
@ -50,10 +46,7 @@
{% endif -%}
{{ hostvars[host]['ctlplane_ip'] ~ ' ' ~
host ~ '.ctlplane' ~ '.' ~ cloud_domain ~ ' ' ~ host ~ '.ctlplane' }}
{% endfor -%}
{{ tripleo_hosts_entries_extra_hosts_entries | default([]) | join('') }}
{% endfor %}
tags:
- tripleo_hosts_entries
@ -64,6 +57,12 @@
path: "{{ tripleo_hosts_entries_hosts_path }}"
# BOF denotes the beginning of the file.
insertbefore: BOF
block: "{{ tripleo_hosts_entries_block }}"
block: |
{{ tripleo_hosts_entries_block }}
{% for host in tripleo_hosts_entries_undercloud_hosts_entries | default([]) +
tripleo_hosts_entries_vip_hosts_entries | default([]) +
tripleo_hosts_entries_extra_hosts_entries | default([]) %}
{{ host }}
{% endfor %}
tags:
- tripleo_hosts_entries