Skip to content

Commit 923f21c

Browse files
authored
Merge pull request #7 from cisagov/improvement/use-drop-in
Write a config drop-ins instead of modifying the systemd-provided config file
2 parents 093f296 + 9fa33b9 commit 923f21c

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ None.
2222
| Variable | Description | Default | Required |
2323
|----------|-------------|---------|----------|
2424
| systemd_resolved_dns_stub_listener | The value to use for the DNSStubListener value in the `systemd-resolved` configuration file. Must be `tcp`, `udp`, or a boolean value. See [here](https://man.archlinux.org/man/resolved.conf.5.en) for more information. | `true` | No |
25+
| systemd_resolved_dropin_config_file | The location of the systemd-resolved drop-in configuration file that will be created. | `/etc/systemd/resolved.conf.d/99-ansible-role-systemd-resolved` | No |
2526
| systemd_resolved_resolv_conf_filename | The location of the target to which `/etc/resolv.conf` will be symlinked. Note that `dynamic_resolv_conf_target_dir` and `static_resolv_conf_target_dir` are role vars that are available for use when defining this variable. See [here](https://man.archlinux.org/man/systemd-resolved.8#/ETC/RESOLV.CONF) for more information. | `"{{ dynamic_resolv_conf_target_dir }}/stub-resolv.conf"` | No |
2627
<!--
2728
| required_variable | Describe its purpose. | n/a | Yes |

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# https://man.archlinux.org/man/resolved.conf.5.en
88
systemd_resolved_dns_stub_listener: true
99

10+
# The location of the systemd-resolved drop-in configuration file that
11+
# will be created.
12+
systemd_resolved_dropin_config_file: /etc/systemd/resolved.conf.d/99-ansible-role-systemd-resolved.conf
13+
1014
# The location of the file to which /etc/resolv.conf will be
1115
# symlinked. The symlink target should normally be one of the
1216
# following files provided by systemd-resolved:

tasks/main.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,26 @@
3232
name:
3333
- systemd-resolved
3434

35-
- name: Set DNSStubListener in the systemd-resolved configuration file
35+
- name: >-
36+
Ensure that the directory where the systemd-resolved drop-in will
37+
live actually exists
38+
ansible.builtin.file:
39+
group: root
40+
mode: 0755
41+
owner: root
42+
path: "{{ systemd_resolved_dropin_config_file | dirname }}"
43+
state: directory
44+
45+
- name: Set DNSStubListener config value for systemd-resolved
3646
community.general.ini_file:
37-
# This config file should already exist, and putting false here
38-
# allows us to avoid ansible-lint warnings about needing to
39-
# specify the group, owner, and mode of the file.
40-
create: false
41-
# This is just to maintain the look and feel of the file as
42-
# provided by systemd-resolved.
47+
group: root
48+
mode: 0644
49+
# This is just to maintain the look and feel of the
50+
# /etc/systemd/resolved.conf file as provided by systemd-resolved.
4351
no_extra_spaces: true
4452
option: DNSStubListener
45-
path: "{{ config_file }}"
53+
owner: root
54+
path: "{{ systemd_resolved_dropin_config_file }}"
4655
section: Resolve
4756
value: "{{ systemd_resolved_dns_stub_listener }}"
4857

vars/default.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
# The location of the systemd-resolved configuration file.
3-
config_file: /etc/systemd/resolved.conf
4-
52
# The directory where systemd-resolved stores the _dynamic_
63
# resolv.conf symlink targets it provides.
74
dynamic_resolv_conf_target_dir: /run/systemd/resolve

0 commit comments

Comments
 (0)