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
18 changes: 18 additions & 0 deletions ansible/hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Ensure hostname is configured
hosts: seed-hypervisor:seed:overcloud:infra-vms:ansible-control
max_fail_percentage: >-
{{ hostname_max_fail_percentage |
default(host_configure_max_fail_percentage) |
default(kayobe_max_fail_percentage) |
default(100) }}
tags:
- hostname
tasks:
- name: Ensure hostname is set
become: true
hostname:
name: "{{ kayobe_custom_hostname }}"
use: "systemd"
when:
- kayobe_customize_hostnames | bool
9 changes: 9 additions & 0 deletions ansible/inventory/group_vars/all/hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
###############################################################################
# Kayobe custom hostname configuration.

# Whether to set custom hostnames. Default is false.
kayobe_customize_hostnames: false

# Custom hostname to set. Default is "{{ inventory_hostname }}".
kayobe_custom_hostname: "{{ inventory_hostname }}"
1 change: 1 addition & 0 deletions ansible/overcloud-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: "hostname.yml"
- import_playbook: "etc-hosts.yml"
- import_playbook: "tuned.yml"
- import_playbook: "sysctl.yml"
Expand Down
5 changes: 3 additions & 2 deletions ansible/roles/etc-hosts/tasks/etc-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
when:
- etc_hosts_gather_facts | default(true)
- etc_hosts_hosts | length > 0
- not kayobe_customize_hostnames | bool

- name: Ensure localhost in /etc/hosts
lineinfile:
Expand All @@ -27,7 +28,7 @@
- name: Ensure hostname does not point to 127.0.1.1 in /etc/hosts
lineinfile:
dest: /etc/hosts
regexp: "^127.0.1.1\\b.*\\s{{ ansible_facts.hostname }}\\b"
regexp: "^127.0.1.1\\b.*\\s{{ kayobe_custom_hostname if (kayobe_customize_hostnames | bool) else ansible_facts.hostname }}\\b"
state: absent
become: True
when: inventory_hostname in etc_hosts_hosts
Expand All @@ -39,7 +40,7 @@
block: |
{% for host in etc_hosts_hosts %}
{% if hostvars[host]['etc_hosts_network'] in hostvars[host].network_interfaces %}
{% set hostnames = [hostvars[host].ansible_facts.nodename, hostvars[host].ansible_facts.hostname] %}
{% set hostnames = [hostvars[host].kayobe_custom_hostname] if (kayobe_customize_hostnames | bool) else [hostvars[host].ansible_facts.nodename, hostvars[host].ansible_facts.hostname] %}
{{ hostvars[host]['etc_hosts_network'] | net_ip(inventory_hostname=host) }} {{ hostnames | unique | join(' ') }}
{% endif %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% for host in groups.get(group, []) %}
{%- if hostvars[host].kolla_overcloud_inventory_pass_through_enabled | default(true) | bool -%}
{{ host }}
{%- endif -%}
{% endif -%}
{% endfor %}

{% endfor %}
Expand Down
31 changes: 31 additions & 0 deletions doc/source/configuration/reference/hosts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,29 @@ AppArmor for the libvirt container
On Ubuntu systems running the ``nova_libvirt`` Kolla container, AppArmor rules
for libvirt are disabled.

Setting the hostname of kayobe-managed hosts
============================================

*tags:*
| ``hostname``

Kayobe can configure the hostname of the hosts it manages via systemd. By
default, this will configure the hostname to match the name in the Ansible
inventory. This can be customised further with the variable
``kayobe_custom_hostname``. This feature is disabled by default, but can be
enabled with the variable ``kayobe_customize_hostnames``.

.. note::

Setting hostnames is intended to be a global feature, rather than per host.
As such, ``kayobe_custom_hostname`` should be set as an extra var instead
of a host var.

.. code-block:: yaml

kayobe_customize_hostnames: true
kayobe_custom_hostname: "{{ inventory_hostname }}"

Adding entries to /etc/hosts
============================
*tags:*
Expand Down Expand Up @@ -1587,6 +1610,14 @@ follows:

etc_hosts_gather_facts: false

Alternatively, if you are configuring hostnames via Kayobe then this task will
skip gathering facts and directly populate ``/etc/hosts`` files based on
``kayobe_custom_hostname``.

.. code-block:: yaml

kayobe_customize_hostnames: true

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:

Expand Down
9 changes: 9 additions & 0 deletions etc/kayobe/hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
###############################################################################
# Kayobe custom hostname configuration.

# Whether to set custom hostnames. Default is false.
#kayobe_customize_hostnames:

# Custom hostname to set. Default is "{{ inventory_hostname }}".
#kayobe_custom_hostname:
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fix all hostnames in a group being merged into a single line in the kolla
overcloud hosts inventory file.
`LP#2158773 <https://bugs.launchpad.net/kayobe/+bug/2158773>`__
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
Adds support for configuring hostnames via Kayobe. This is disabled by
default; it can be enabled by setting ``kayobe_customize_hostnames`` to
``true``. By default, Kayobe will use the Ansible inventory hostname. This
can be overriden by setting ``kayobe_custom_hostname``.