Skip to content

Commit a71d894

Browse files
committed
Update tasks and Molecule tests to add/test functionality
1 parent c282b73 commit a71d894

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

molecule/default/tests/test_default.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,34 @@
44
import os
55

66
# Third-Party Libraries
7-
import pytest
87
import testinfra.utils.ansible_runner
98

109
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
1110
os.environ["MOLECULE_INVENTORY_FILE"]
1211
).get_hosts("all")
1312

1413

15-
@pytest.mark.parametrize("x", [True])
16-
def test_packages(host, x):
17-
"""Run a dummy test, just to show what one would look like."""
18-
assert x
14+
def test_packages(host):
15+
"""Verify that the expected packages are installed/uninstalled."""
16+
assert host.package(
17+
"systemd-resolved"
18+
).is_installed, "The package systemd-resolved is not installed."
19+
assert not host.package(
20+
"resolvconf"
21+
).is_installed, "The package resolvconf is installed."
22+
23+
24+
def test_symlink(host):
25+
"""Verify that /etc/resolv.conf is the expected symlink."""
26+
f = host.file("/etc/resolv.conf")
27+
assert f.is_symlink, "/etc/resolv.conf is not a symlink."
28+
assert (
29+
f.linked_to == "/run/systemd/resolve/stub-resolv.conf"
30+
), "/etc/resolv.conf is not a symlink to /run/systemd/resolve/stub-resolv.conf."
31+
32+
33+
def test_services(host):
34+
"""Verify that the expected services are present."""
35+
s = host.service("systemd-resolved.service")
36+
assert s.exists, "systemd-resolved.service does not exist."
37+
assert s.is_enabled, "systemd-resolved.service is not enabled."

tasks/main.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
---
2-
# tasks file for skeleton
2+
- name: Install systemd-resolved
3+
ansible.builtin.package:
4+
name:
5+
- systemd-resolved
6+
7+
- name: Ensure resolvconf is not installed
8+
ansible.builtin.package:
9+
name:
10+
- resolvconf
11+
state: absent
12+
13+
- name: Create /etc/resolv.conf symlink
14+
ansible.builtin.file:
15+
# If a file is already present at /etc/resolv.conf then just
16+
# delete it.
17+
force: true
18+
group: root
19+
mode: u=rw,g=r,o=r
20+
owner: root
21+
path: /etc/resolv.conf
22+
src: /run/systemd/resolve/stub-resolv.conf
23+
state: link
24+
25+
- name: Enable systemd-resolved
26+
ansible.builtin.service:
27+
enabled: true
28+
name: systemd-resolved.service

0 commit comments

Comments
 (0)