From 6f1703216b5068db1700e3e72e04aa508e368fdb Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 18 Oct 2020 16:44:11 +0300 Subject: fix(sane_debian_system): set hostname via Ansible --- roles/sane_debian_system/subplot.md | 7 +------ roles/sane_debian_system/subplot.py | 19 +++++++++++++++++++ roles/sane_debian_system/subplot.yaml | 3 +++ roles/sane_debian_system/tasks/env.yml | 8 ++------ 4 files changed, 25 insertions(+), 12 deletions(-) (limited to 'roles') diff --git a/roles/sane_debian_system/subplot.md b/roles/sane_debian_system/subplot.md index 0944602..b9c47e9 100644 --- a/roles/sane_debian_system/subplot.md +++ b/roles/sane_debian_system/subplot.md @@ -15,13 +15,8 @@ and the host has the apt-transport-https package installed and the host has the locales package installed and the host has the ntp package installed and the host has an empty /etc/apt/sources.list.d directory -~~~ - -FIXME: this step doesn't work, since the role doesn't currently tell -the kernel the new hostname. - -~~~ and the host has hostname saneone +and the host has saneone in /etc/hosts for 127.0.1.1 ~~~ ~~~{#sane1.yml .file .yaml} diff --git a/roles/sane_debian_system/subplot.py b/roles/sane_debian_system/subplot.py index 8262479..f45eb2b 100644 --- a/roles/sane_debian_system/subplot.py +++ b/roles/sane_debian_system/subplot.py @@ -1,3 +1,6 @@ +import logging + + def host_has_package_installed(ctx, package=None): assert_eq = globals()["assert_eq"] qemu = ctx["qemu"] @@ -27,3 +30,19 @@ def host_hostname_is(ctx, hostname=None): assert_eq(exit, 0) actual = output.decode("UTF8").splitlines()[-1] assert_eq(actual, hostname) + + +def host_hostname_has_address(ctx, hostname=None, addr=None): + assert_eq = globals()["assert_eq"] + + logging.debug(f"host_hostname_has_address:") + qemu = ctx["qemu"] + output, exit = qemu.ssh(["cat", "/etc/hosts"]) + assert_eq(exit, 0) + logging.debug(f" /etc/hosts: {output!r}") + actual = output.decode("UTF8") + logging.debug(f" /etc/hosts: {actual!r}") + wordlines = [line.split() for line in actual.splitlines()] + matches = [words for words in wordlines if len(words) == 2 and words[1] == hostname] + logging.debug(f" matches: {matches!r}") + assert_eq(matches, [[addr, hostname]]) diff --git a/roles/sane_debian_system/subplot.yaml b/roles/sane_debian_system/subplot.yaml index 4d7911c..9ac1ee3 100644 --- a/roles/sane_debian_system/subplot.yaml +++ b/roles/sane_debian_system/subplot.yaml @@ -6,3 +6,6 @@ - then: the host has hostname {hostname} function: host_hostname_is + +- then: the host has {hostname} in /etc/hosts for {addr} + function: host_hostname_has_address diff --git a/roles/sane_debian_system/tasks/env.yml b/roles/sane_debian_system/tasks/env.yml index c62fca4..3b6ae9e 100644 --- a/roles/sane_debian_system/tasks/env.yml +++ b/roles/sane_debian_system/tasks/env.yml @@ -3,12 +3,8 @@ name: dbus - name: set /etc/hostname - copy: - content: "{{ hostname }}" - dest: /etc/hostname - owner: root - group: root - mode: 0444 + hostname: + name: "{{ hostname }}" when: hostname is defined - name: add hostname to /etc/hosts -- cgit v1.2.1