From a1525abd6b3db65f5ebe3a6f7dbb2a9f749eb1a6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 10 Oct 2020 14:56:50 +0300 Subject: test(sane_debian_system): add subplot scenarios --- roles/sane_debian_system/defaults/main.yml | 3 +++ roles/sane_debian_system/subplot.md | 32 ++++++++++++++++++++++++++++++ roles/sane_debian_system/subplot.py | 29 +++++++++++++++++++++++++++ roles/sane_debian_system/subplot.yaml | 8 ++++++++ roles/sane_debian_system/tasks/main.yml | 5 +++++ roles/unix_users/tasks/main.yml | 2 +- 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 roles/sane_debian_system/subplot.md create mode 100644 roles/sane_debian_system/subplot.py create mode 100644 roles/sane_debian_system/subplot.yaml (limited to 'roles') diff --git a/roles/sane_debian_system/defaults/main.yml b/roles/sane_debian_system/defaults/main.yml index 9e2ca84..95eeb42 100644 --- a/roles/sane_debian_system/defaults/main.yml +++ b/roles/sane_debian_system/defaults/main.yml @@ -1,5 +1,8 @@ # These are the variables expected by this role. +sane_debian_system_version: null + + # The desired hostname. Default is empty, which means hostname won't # be set. hostname: "" diff --git a/roles/sane_debian_system/subplot.md b/roles/sane_debian_system/subplot.md new file mode 100644 index 0000000..0944602 --- /dev/null +++ b/roles/sane_debian_system/subplot.md @@ -0,0 +1,32 @@ +# Role `sane_debian_system` – set up a manageable Debian system + +This role sets up a Debian system so that it can be managed with +Ansible in a reasonable way. + +## Minimally sane Debian system + +~~~scenario +given a host running Debian +when I use role sane_debian_system +and I use variables from sane1.yml +and I run the playbook +then the host has the sudo package installed +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 +~~~ + +~~~{#sane1.yml .file .yaml} +sane_debian_system_version: 0 + +debian_codename: buster +hostname: saneone +~~~ diff --git a/roles/sane_debian_system/subplot.py b/roles/sane_debian_system/subplot.py new file mode 100644 index 0000000..8262479 --- /dev/null +++ b/roles/sane_debian_system/subplot.py @@ -0,0 +1,29 @@ +def host_has_package_installed(ctx, package=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["dpkg", "--status", package]) + assert_eq(exit, 0) + installed = False + for line in output.decode("UTF8").splitlines(): + if line.startswith("Status:") and " installed" in line: + installed = True + break + assert installed + + +def host_directory_is_empty(ctx, pathname=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["find", "/etc/apt/sources.list.d"]) + assert_eq(exit, 0) + for line in output.decode("UTF8").splitlines(): + assert "/etc/apt/sources.list.d/" not in line + + +def host_hostname_is(ctx, hostname=None): + assert_eq = globals()["assert_eq"] + qemu = ctx["qemu"] + output, exit = qemu.ssh(["hostname"]) + assert_eq(exit, 0) + actual = output.decode("UTF8").splitlines()[-1] + assert_eq(actual, hostname) diff --git a/roles/sane_debian_system/subplot.yaml b/roles/sane_debian_system/subplot.yaml new file mode 100644 index 0000000..4d7911c --- /dev/null +++ b/roles/sane_debian_system/subplot.yaml @@ -0,0 +1,8 @@ +- then: the host has the {package} package installed + function: host_has_package_installed + +- then: the host has an empty {pathname} directory + function: host_directory_is_empty + +- then: the host has hostname {hostname} + function: host_hostname_is diff --git a/roles/sane_debian_system/tasks/main.yml b/roles/sane_debian_system/tasks/main.yml index dcb3b60..530d9bf 100644 --- a/roles/sane_debian_system/tasks/main.yml +++ b/roles/sane_debian_system/tasks/main.yml @@ -1,2 +1,7 @@ +- name: "sane_debian_system_version" + shell: | + [ "{{ sane_debian_system_version }}" = ""0 ] || \ + (echo "Unexpected version {{ sane_debian_system_version }}" 1>&2; exit 1) + - include: apt.yml - include: env.yml diff --git a/roles/unix_users/tasks/main.yml b/roles/unix_users/tasks/main.yml index 7681632..097815f 100644 --- a/roles/unix_users/tasks/main.yml +++ b/roles/unix_users/tasks/main.yml @@ -2,7 +2,7 @@ shell: | [ "{{ unix_users_version }}" = "0" ] || \ (echo "Unexpected version {{ unix_users_version }}" 1>&2; exit 1) - + - name: create system users with_items: "{{ unix_users }}" user: -- cgit v1.2.1