Use hostnamectl to set the container hostname

This change sets the hostname of containers using the hostnamectl
command which has several enhancements over legacy method. By using
hostnamectl the command will validate the hostname for correctness
ensuring the container hostnames are conforming the the RFC.

The old methods have been removed and the command has been made part of
the handlers and will be run after the activation of dbus.

Change-Id: I158a5deb0685d2dcd436d7dd92caecb9966a025e
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-03-16 17:17:03 -05:00 committed by Kevin Carter (cloudnull)
parent beeb8573f6
commit a2fc120d06
2 changed files with 13 additions and 21 deletions

View File

@ -72,13 +72,6 @@
when:
- lxc_container_enable_resolved | bool
- name: Enable hostnamed
systemd:
name: systemd-hostnamed
state: started
enabled: true
daemon_reload: true
- name: Enable dbus
systemd:
name: dbus
@ -90,6 +83,19 @@
systemd:
daemon_reload: true
- name: Start hostnamed
systemd:
name: systemd-hostnamed
state: started
enabled: true
daemon_reload: true
listen: Enable hostnamed
- name: Set hostnamectl name
command: "/usr/bin/hostnamectl --static --pretty --transient set-hostname {{ inventory_hostname | replace('_', '-') | quote }}"
changed_when: false
listen: Enable hostnamed
# NOTE(hwoarang) openSUSE randomly fails to start the service
# with an error like the following one
# sysctl-container.service: Failed at step CGROUP spawning /sbin/sysctl: No such device

View File

@ -237,20 +237,6 @@
mode: "0644"
remote_user: root
- name: Create hostname
copy:
dest: "/etc/hostname"
content: "{{ inventory_hostname | replace('_', '-') }}"
owner: "root"
group: "root"
mode: "0644"
remote_user: root
- name: Setup hostname
command: hostname -F /etc/hostname
changed_when: false
remote_user: root
- name: Ensure the hostnamed override directory exists
file:
path: "/etc/systemd/system/systemd-hostnamed.service.d"