108 lines
3.6 KiB
YAML
108 lines
3.6 KiB
YAML
---
|
||
# Copyright 2019 Red Hat, Inc.
|
||
# All Rights Reserved.
|
||
#
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||
# not use this file except in compliance with the License. You may obtain
|
||
# a copy of the License at
|
||
#
|
||
# http://www.apache.org/licenses/LICENSE-2.0
|
||
#
|
||
# Unless required by applicable law or agreed to in writing, software
|
||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||
# License for the specific language governing permissions and limitations
|
||
# under the License.
|
||
|
||
|
||
- name: Create temporary file for hosts
|
||
become: true
|
||
tempfile:
|
||
state: file
|
||
suffix: tmphosts
|
||
register: tripleo_hosts_entries_tmp_hosts
|
||
check_mode: false
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Prepare temporary /etc/hosts
|
||
become: true
|
||
copy:
|
||
remote_src: true
|
||
src: "{{ tripleo_hosts_entries_hosts_path }}"
|
||
dest: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||
mode: preserve
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Remove old Heat hosts configuration (if present)
|
||
become: true
|
||
blockinfile:
|
||
state: absent
|
||
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||
block: ""
|
||
marker: "# {mark}"
|
||
marker_begin: "HEAT_HOSTS_START - Do not edit manually within this section!"
|
||
marker_end: "HEAT_HOSTS_END"
|
||
register: tripleo_hosts_entries_heat_marker
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Render out the hosts entries
|
||
run_once: true
|
||
set_fact:
|
||
tripleo_hosts_entries_block: |
|
||
{% for host in groups['allovercloud'] -%}
|
||
{{ hostvars[host][hostvars[host]['hostname_resolve_network'] ~ '_ip'] ~ ' ' ~
|
||
host ~ '.' ~ cloud_domain ~ ' ' ~ host }}
|
||
{# ## NOTE(hjensas): The Undercloud Minion has no networks, need to check for that here. -#}
|
||
{% if hostvars[host]['role_networks'] is not none -%}
|
||
{% set _role_networks = hostvars[host]['role_networks'] | default ([]) -%}
|
||
{% set _networks = (enabled_networks | default([])) | intersect(_role_networks) -%}
|
||
{% for network in _networks -%}
|
||
{{ hostvars[host][networks[network]['name_lower'] ~ '_ip'] ~ ' ' ~
|
||
host ~ '.' ~ network.lower() ~ '.' ~ cloud_domain ~ ' ' ~
|
||
host ~ '.' ~ network.lower() }}
|
||
{% endfor -%}
|
||
{% endif -%}
|
||
{{ hostvars[host]['ctlplane_ip'] ~ ' ' ~
|
||
host ~ '.ctlplane' ~ '.' ~ cloud_domain ~ ' ' ~ host ~ '.ctlplane' }}
|
||
{% endfor %}
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Prepare new /etc/hosts
|
||
become: true
|
||
blockinfile:
|
||
create: true
|
||
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||
# BOF denotes the beginning of the file.
|
||
insertbefore: BOF
|
||
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 %}
|
||
register: tripleo_hosts_entries_new_entries
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Update /etc/hosts contents (if changed)
|
||
become: true
|
||
# cp preserves the inode of the existing file tripleo_hosts_entries_hosts_path
|
||
command: cp "{{ tripleo_hosts_entries_tmp_hosts.path }}" "{{ tripleo_hosts_entries_hosts_path }}"
|
||
when: tripleo_hosts_entries_heat_marker.changed or tripleo_hosts_entries_new_entries.changed
|
||
tags:
|
||
- tripleo_hosts_entries
|
||
|
||
- name: Clean up temporary hosts file
|
||
become: true
|
||
file:
|
||
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||
state: absent
|
||
when: tripleo_hosts_entries_tmp_hosts.path is defined
|
||
tags:
|
||
- tripleo_hosts_entries
|