Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/control-host-configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- import_playbook: "network.yml"
- import_playbook: "firewall.yml"
- import_playbook: "fail2ban.yml"
- import_playbook: "etc-hosts.yml"
- import_playbook: "tuned.yml"
- import_playbook: "sysctl.yml"
- import_playbook: "time.yml"
Expand Down
9 changes: 1 addition & 8 deletions ansible/etc-hosts.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure /etc/hosts is configured
hosts: overcloud
hosts: seed-hypervisor:seed:overcloud:infra-vms:ansible-control
max_fail_percentage: >-
{{ etc_hosts_max_fail_percentage |
default(host_configure_max_fail_percentage) |
Expand All @@ -9,12 +9,5 @@
tags:
- etc-hosts
tasks:
# NOTE(mgoddard): Need to ensure that all hosts have facts available.
- import_role:
name: gather-facts-delegated
tags:
- gather-facts-delegated
when: etc_hosts_gather_facts | default(true)

- import_role:
name: etc-hosts
1 change: 1 addition & 0 deletions ansible/infra-vm-host-configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- import_playbook: "network.yml"
- import_playbook: "firewall.yml"
- import_playbook: "fail2ban.yml"
- import_playbook: "etc-hosts.yml"
- import_playbook: "tuned.yml"
- import_playbook: "sysctl.yml"
- import_playbook: "disable-glean.yml"
Expand Down
6 changes: 6 additions & 0 deletions ansible/inventory/group_vars/overcloud/etc-hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Which hosts to add to /etc/hosts
etc_hosts_hosts: "{{ groups['overcloud'] }}"

# Which network to use for the IP address in /etc/hosts
etc_hosts_network: "{{ internal_net_name }}"
5 changes: 4 additions & 1 deletion ansible/roles/etc-hosts/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
customize_etc_hosts: true

# List of hosts to add to /etc/hosts.
etc_hosts_hosts: "{{ groups['overcloud'] }}"
etc_hosts_hosts: []

# Which network to use for host entries in /etc/hosts
etc_hosts_network: "{{ undef() }}"

# Dictionary of custom /etc/hosts entries.
# Each key is added as a hostname,
Expand Down
31 changes: 26 additions & 5 deletions ansible/roles/etc-hosts/tasks/etc-hosts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
# NOTE(mgoddard): Need to ensure that all hosts have facts available.
- include_role:
name: gather-facts-delegated
tags:
- gather-facts-delegated
vars:
gather_facts_delegated_limit_hosts: "{{ etc_hosts_hosts }}"
when:
- etc_hosts_gather_facts | default(true)
- etc_hosts_hosts | length > 0

- name: Ensure localhost in /etc/hosts
lineinfile:
dest: /etc/hosts
Expand Down Expand Up @@ -26,18 +37,28 @@
marker: "# {mark} ANSIBLE GENERATED HOSTS"
block: |
{% for host in etc_hosts_hosts %}
{% if hostvars[host].internal_net_name in hostvars[host].network_interfaces %}
{% if hostvars[host]['etc_hosts_network'] in hostvars[host].network_interfaces %}
{% set hostnames = [hostvars[host].ansible_facts.nodename, hostvars[host].ansible_facts.hostname] %}
{{ hostvars[host].internal_net_name | net_ip(inventory_hostname=host) }} {{ hostnames | unique | join(' ') }}
{{ hostvars[host]['etc_hosts_network'] | net_ip(inventory_hostname=host) }} {{ hostnames | unique | join(' ') }}
{% endif %}
{% endfor %}
become: True
when:
- etc_hosts_hosts | length > 0
- etc_hosts_network | mandatory is truthy
# Skip hosts that do not have a valid internal network interface.
- etc_hosts_network in network_interfaces

- name: Add custom entries to /etc/hosts
blockinfile:
dest: /etc/hosts
marker: "# {mark} ANSIBLE GENERATED CUSTOM HOSTS"
block: |
{% for item in custom_etc_hosts_entries | dict2items %}
{{ item.value }} {{ item.key }}
{% endfor %}
become: True
when:
# Skip hosts that do not have a valid internal network interface.
- internal_net_name in network_interfaces
when: custom_etc_hosts_entries | length > 0

# NOTE(osmanlicilegi): The distribution might come with cloud-init installed, and manage_etc_hosts
# configuration enabled. If so, it will override the file /etc/hosts from cloud-init templates at
Expand Down
1 change: 1 addition & 0 deletions ansible/seed-host-configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- import_playbook: "network.yml"
- import_playbook: "firewall.yml"
- import_playbook: "fail2ban.yml"
- import_playbook: "etc-hosts.yml"
- import_playbook: "tuned.yml"
- import_playbook: "sysctl.yml"
- import_playbook: "ip-routing.yml"
Expand Down
1 change: 1 addition & 0 deletions ansible/seed-hypervisor-host-configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- import_playbook: "network.yml"
- import_playbook: "firewall.yml"
- import_playbook: "fail2ban.yml"
- import_playbook: "etc-hosts.yml"
- import_playbook: "tuned.yml"
- import_playbook: "sysctl.yml"
- import_playbook: "ip-routing.yml"
Expand Down