Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rec: add copy files for *-from-file configuration directives #94

Merged
merged 5 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pdns_rec_install_epel: True
```

By default, install EPEL to satisfy some PowerDNS Recursor dependencies like `protobuf`.
To skip the installtion of EPEL set `pdns_rec_install_epel` to `False`.
To skip the installation of EPEL set `pdns_rec_install_epel` to `False`.

```yaml
pdns_rec_package_name: "{{ default_pdns_rec_package_name }}"
Expand Down Expand Up @@ -182,6 +182,23 @@ pdns_rec_service_overrides:
Dict with overrides for the service (systemd only).
This can be used to change any systemd settings in the `[Service]` category

```yaml
pdns_rec_config_from_files_dir_mode: 0750
pdns_rec_config_from_files: []
#pdns_rec_config_from_files:
# - dest: "/var/lib/pdns-recursor/from-files/forward-zones.txt"
# src: "files/forward-zones/forward.txt"
```

List of files to copy to the PowerDNS Recursor instance, could be used for the `*-from-file` settings in the `recursor.conf` configuration file.
The `pdns_rec_config_from_files_dir_mode` allow to change the mode of files if required.
Copy link
Contributor

@npmdnl npmdnl Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows changing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.


```yaml
pdns_rec_config_include_dir_mode: 0750
```

The `pdns_rec_config_include_dir_mode` will change the mode of directories form `include-dir` settings, in case one of them required some writing permissions.

## Example Playbooks

Bind to `203.0.113.53` on port `5300` and allow only traffic from the `198.51.100.0/24` subnet:
Expand Down
7 changes: 7 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ pdns_rec_config_lua_file_content: ""
pdns_rec_config_dns_script: "{{ pdns_rec_config_dir }}/dns-script.lua"
pdns_rec_config_dns_script_file_content: ""

# Mode for directories from include-dir
pdns_rec_config_include_dir_mode: 0750

# Directories and files required by recursor configuration
pdns_rec_config_from_files_dir_mode: 0750
pdns_rec_config_from_files: []

# Dict containing all configuration options, except for the
# "config-dir", "setuid" and "setgid" directives in YAML format.
pdns_rec_config: {}
Expand Down
29 changes: 28 additions & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,33 @@
state: directory
owner: "{{ pdns_rec_file_owner }}"
group: "{{ pdns_rec_file_group }}"
mode: 0750
mode: "{{ pdns_rec_config_include_dir_mode }}"
when: "pdns_rec_config['include-dir'] is defined"
register: _pdns_recursor_configuration_include_dir
npmdnl marked this conversation as resolved.
Show resolved Hide resolved

- block:

- name: Ensure that the PowerDNS Recursor configuration from-files directory exists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block indentation require some extra indentation of tasks inside it.
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_blocks.html#grouping-tasks-with-blocks

ansible.builtin.file:
name: "{{ item.dest | dirname }}"
state: directory
owner: "{{ pdns_rec_file_owner }}"
group: "{{ pdns_rec_file_group }}"
mode: "{{ pdns_rec_config_from_files_dir_mode }}"
loop: "{{ pdns_rec_config_from_files }}"

- name: Copy the PowerDNS Recursor configuration from-files files
ansible.builtin.copy:
content: "{{ item.content | default(omit) }}"
src: "{{ item.src | default(omit) }}"
dest: "{{ item.dest }}"
owner: "{{ pdns_rec_file_owner }}"
group: "{{ pdns_rec_file_group }}"
mode: "{{ pdns_rec_config_from_files_dir_mode }}"
loop: "{{ pdns_rec_config_from_files }}"
register: _pdns_recursor_configuration_from_files

when: "pdns_rec_config_from_files | length > 0"

- name: Generate the PowerDNS Recursor Lua config-file
copy:
Expand Down Expand Up @@ -79,6 +104,8 @@
when: not pdns_rec_disable_handlers
and pdns_rec_service_state != 'stopped'
and (_pdns_recursor_override_unit.changed
or _pdns_recursor_configuration_include_dir.changed
or _pdns_recursor_configuration.changed
or _pdns_recursor_configuration_from_files.changed
or _pdns_recursor_lua_file_configuraton.changed
or _pdns_recursor_dns_script_configuration.changed)