diff --git a/handlers/main.yml b/handlers/main.yml index dab0db6..ea2ff7b 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -73,13 +73,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 @@ -91,6 +84,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 diff --git a/tasks/lxc_container_config.yml b/tasks/lxc_container_config.yml index 6b3ecc6..79ea79b 100644 --- a/tasks/lxc_container_config.yml +++ b/tasks/lxc_container_config.yml @@ -245,20 +245,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"