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
5 changes: 5 additions & 0 deletions ansible/roles/etc-hosts/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ customize_etc_hosts: true

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

# Dictionary of custom /etc/hosts entries.
# Each key is added as a hostname,
# Each value is added as an IP.
custom_etc_hosts_entries: {}
3 changes: 3 additions & 0 deletions ansible/roles/etc-hosts/tasks/etc-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
{{ hostvars[host].internal_net_name | net_ip(inventory_hostname=host) }} {{ hostnames | unique | join(' ') }}
{% endif %}
{% endfor %}
{% 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.
Expand Down
9 changes: 9 additions & 0 deletions doc/source/configuration/reference/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,15 @@ follows:

etc_hosts_gather_facts: false

Custom entries can be added to the ``custom_etc_hosts_entries`` dictionary.
Each key is treated as a hostname and each value is the IP, for example:

.. code-block:: yaml

custom_etc_hosts_entries:
foo.exaple.com: 1.2.3.4
bar.exaple.com: 5.6.7.8

Installing packages required by Kolla Ansible
=============================================
*tags:*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,7 @@ controller_swap:

# Generate a password for libvirt SASL authentication.
compute_libvirt_sasl_password: "{% raw %}{{ lookup('password', '/tmp/libvirt-sasl-password') }}{% endraw %}"

# Add a custom entry to /etc/hosts.
custom_etc_hosts_entries:
foo.example.com: 127.0.0.88
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,10 @@ def test_swap(host):
assert len(swapon) > 1
swap_devs = [swap.split()[0] for swap in swapon[1:]]
assert "/swapfile" in swap_devs


def test_etc_hosts(host):
hosts_entries = host.check_output("cat /etc/hosts")
assert "127.0.0.88 foo.example.com" in hosts_entries
ping_result = host.check_output("ping -c 1 foo.example.com")
assert "1 received" in ping_result
8 changes: 8 additions & 0 deletions releasenotes/notes/custom-etc-hosts-f85fcff9aac727aa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
Added a new variable, ``custom_etc_hosts_entries``, for appending entries
to ``/etc/hosts``. This is a generic mechanism which, unlike
``etc_hosts_hosts``, can be used to add hosts outside of the Kayobe
inventory. ``custom_etc_hosts_entries`` is a dictionary, where each key is
a hostname and each value is an IP.