Skip to content

Commit

Permalink
Allow to manage systemd overrides (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
atosatto authored Jul 13, 2018
1 parent bacd536 commit ce468ee
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.1.1 (To be released)

NEW FEATURES:
- Allow to manage systemd overrides ([\#13](https://github.com/PowerDNS/pdns-ansible/pull/13))

## v1.1.0 (2018-06-25)

IMPROVEMENTS:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ dnsdist_config: ""

Additional dnsdist configuration to be injected verbatim in the `dnsdist.conf` file.

```yaml
pdns_service_overrides: {}
```

Dict with overrides for the service (systemd only).
This can be used to change any systemd settings in the `[Service]` category.

## Example Playbook

Deploy dnsdist in front of Quad9 and enable the web monitoring interface
Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ dnsdist_carbonserver: ""
# Additional dnsdist configuration to be
# injected into dnsdist's configuration file.
dnsdist_config: ""

# Dict with overrides for the service (systemd only)
dnsdist_service_overrides: {}
# dnsdist_service_overrides:
# LimitNOFILE: 10000
4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
service:
name: dnsdist
state: restarted

- name: reload systemd and restart dnsdist
command: systemctl daemon-reload
notify: restart dnsdist
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ galaxy_info:
- vivid
- wily
- xenial
- bionic
galaxy_tags:
- dnsdist
- dns
Expand Down
9 changes: 9 additions & 0 deletions molecule/dnsdist-13/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ platforms:
groups:
- dnsdist

- name: ubuntu-1804
image: ubuntu:18.04
dockerfile_tpl: debian-systemd
groups:
- dnsdist

- name: debian-9
image: debian:9
dockerfile_tpl: debian-systemd
Expand All @@ -45,6 +51,9 @@ provisioner:
prepare: ../resources/prepare.yml
lint:
name: ansible-lint
options:
# excludes "systemctl used in place of systemd module"
x: ["ANSIBLE0006"]

lint:
name: yamllint
Expand Down
9 changes: 9 additions & 0 deletions molecule/dnsdist-master/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ platforms:
groups:
- dnsdist

- name: ubuntu-1804
image: ubuntu:18.04
dockerfile_tpl: debian-systemd
groups:
- dnsdist

- name: debian-9
image: debian:9
dockerfile_tpl: debian-systemd
Expand All @@ -45,6 +51,9 @@ provisioner:
prepare: ../resources/prepare.yml
lint:
name: ansible-lint
options:
# excludes "systemctl used in place of systemd module"
x: ["ANSIBLE0006"]

lint:
name: yamllint
Expand Down
12 changes: 12 additions & 0 deletions molecule/resources/tests/all/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ def test_service(host):
s = host.ansible('service', 'name=dnsdist state=started enabled=yes')

assert s["changed"] is False


def systemd_override(host):
smgr = host.ansible("setup")["ansible_facts"]["ansible_service_mgr"]
if smgr == 'systemd':
fname = '/etc/systemd/system/pdns.service.d/override.conf'
f = host.file(fname)

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert 'LimitCORE=infinity' in f.content
3 changes: 3 additions & 0 deletions molecule/resources/vars/dnsdist-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
##

dnsdist_install_debug_symbols_package: True

dnsdist_service_overrides:
LimitCORE: infinity
31 changes: 31 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

- block:

- name: Ensure the override directory exists (systemd)
file:
name: "/etc/systemd/system/dnsdist.service.d"
state: directory
owner: root
group: root

- name: Override the dnsdist unit (systemd)
template:
src: "override-service.systemd.conf.j2"
dest: "/etc/systemd/system/dnsdist.service.d/override.conf"
owner: root
group: root
notify: reload systemd and restart dnsdist

when: dnsdist_service_overrides != {}
and ansible_service_mgr == "systemd"

- name: Add the dnsdist configuration
template:
src: dnsdist.conf.j2
dest: /etc/dnsdist/dnsdist.conf
owner: "root"
group: "root"
mode: 0640
validate: dnsdist -C %s --check-config 2>&1
notify: restart dnsdist
10 changes: 1 addition & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
tags:
- install

- name: Add the dnsdist configuration
template:
src: dnsdist.conf.j2
dest: /etc/dnsdist/dnsdist.conf
owner: "root"
group: "root"
mode: 0640
validate: dnsdist -C %s --check-config 2>&1
notify: restart dnsdist
- include: configure.yml
tags:
- configure

Expand Down
4 changes: 4 additions & 0 deletions templates/override-service.systemd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Service]
{% for k, v in dnsdist_service_overrides.items() %}
{{ k }}={{ v }}
{% endfor %}

0 comments on commit ce468ee

Please sign in to comment.