forked from osism/ansible-collection-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolvconf.py
87 lines (65 loc) · 3.31 KB
/
resolvconf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from .util.util import get_variable, jinja_list_concat
def test_resolvconf_minimum_number_of_nameservers(host):
"""Check the minimum number of nameservers."""
nameservers = get_variable(host, "resolvconf_nameserver")
minimum_ns = get_variable(host, "resolvconf_minimum_number_of_nameservers")
assert len(nameservers) >= minimum_ns
def test_resolvconf_service_disabled(host):
"""Check if the resolvconf service is disabled."""
service = host.service("resolvconf")
assert not service.is_enabled
assert not service.is_running
def test_resolved_conf_file(host):
"""Check if the resolved.conf file exists and its permissions."""
resolved_file = host.file("/etc/systemd/resolved.conf")
assert resolved_file.exists
assert resolved_file.user == "root"
assert resolved_file.group == "root"
assert resolved_file.mode == 0o644
assert "DO NOT EDIT THIS FILE BY HAND" in resolved_file.content_string
def test_resolvconf_content(host):
"""Check content of /etc/systemd/resolved.conf."""
file_content = host.file("/etc/systemd/resolved.conf").content_string
assert f"Domains={get_variable(host, 'resolvconf_search')}" in file_content
dnssec = get_variable(host, "resolvconf_dnssec")
if type(dnssec) is str:
assert f"DNSSEC={dnssec}" in file_content
else:
assert f"DNSSEC={'yes' if dnssec == True else 'no'}" in file_content
fallback_dns_servers = get_variable(host, "resolvconf_fallback_nameserver")
if len(fallback_dns_servers) > 0:
for fallback_dns_server in fallback_dns_servers:
assert fallback_dns_server in file_content
dnstls = get_variable(host, "resolvconf_dns_over_tls")
if type(dnstls) is str:
assert f"DNSOverTLS={dnstls}" in file_content
else:
assert f"DNSOverTLS={'yes' if dnstls == True else 'no'}" in file_content
resolvecache = get_variable(host, "resolvconf_cache")
if type(resolvecache) is str:
assert f"Cache={resolvecache}" in file_content
else:
assert f"Cache={'yes' if resolvecache == True else 'no'}" in file_content
cachelocal = get_variable(host, "resolvconf_cache_from_localhost")
assert f"CacheFromLocalhost={'yes' if cachelocal == True else 'no'}" in file_content
etchosts = get_variable(host, "resolvconf_read_etc_hosts")
assert f"ReadEtcHosts={'yes' if etchosts == True else 'no'}" in file_content
expected_nameservers = get_variable(host, "resolvconf_nameserver")
expected_nameservers_default = get_variable(host, "resolvconf_nameserver_default")
expected_nameservers_extra = get_variable(host, "resolvconf_nameserver_extra")
expected_nameservers = jinja_list_concat(
expected_nameservers, [expected_nameservers_default, expected_nameservers_extra]
)
assert type(expected_nameservers) is list
for expected in expected_nameservers:
assert expected in file_content
def test_systemd_resolved_service_enabled(host):
"""Check if the systemd-resolved service is enabled and running."""
service = host.service("systemd-resolved")
assert service.is_enabled
assert service.is_running
def test_resolvconf_file_is_symlink(host):
"""Check if /etc/resolv.conf is a symlink."""
resolvconf_file = get_variable(host, "resolvconf_file")
f = host.file(resolvconf_file)
assert f.is_symlink