Use built-in roles and move /etc/resolv.conf replacement into tasks

This commit is contained in:
Alex 2020-05-16 22:10:28 +02:00
parent 7e4eba3ac9
commit fa51f71e57
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
3 changed files with 21 additions and 54 deletions

View File

@ -1,18 +1,3 @@
- name: Reload unbound
systemd:
name: unbound
state: reloaded
- name: Enable unbound
systemd:
name: unbound
enabled: yes
state: restarted
daemon_reload: yes
- name: Set unbound as default dns
replace:
path: /etc/resolv.conf
regexp: "^nameserver.*$"
replace: "nameserver 127.0.0.1"
- name: Disable systemd-resolved - name: Disable systemd-resolved
systemd: systemd:
name: systemd-resolved name: systemd-resolved
@ -21,8 +6,3 @@
notify: notify:
- Enable unbound - Enable unbound
- Set unbound as default dns - Set unbound as default dns
- name: Save netfilter rules
command:
argv:
- '/usr/sbin/netfilter-persistent'
- 'save'

View File

@ -1,13 +1,3 @@
- name: Install Unbound
apt:
install_recommends: no
name: unbound
state: present
cache_valid_time: 3600
notify: Disable systemd-resolved
tags:
- setup
- packages
- name: Copy configuration files - name: Copy configuration files
loop: loop:
- internal.conf - internal.conf
@ -16,30 +6,16 @@
template: template:
follow: yes follow: yes
src: '{{ item }}.j2' src: '{{ item }}.j2'
dest: /etc/unbound/{{ item }} dest: "/etc/unbound/{{ item }}"
notify: notify: Run service actions
- Reload unbound
tags: tags:
- update - config
- unbound - unbound
- name: Allow Unbound through iptables - name: Set unbound as default dns
loop: replace:
- { ipv: 'ipv4', proto: 'tcp' } path: /etc/resolv.conf
- { ipv: 'ipv6', proto: 'tcp' } regexp: "^nameserver.*$"
- { ipv: 'ipv4', proto: 'udp' } replace: "nameserver 127.0.0.1"
- { ipv: 'ipv6', proto: 'udp' }
iptables:
chain: INPUT
ctstate:
- NEW
- ESTABLISHED
- RELATED
destination_port: "53"
jump: ACCEPT
ip_version: '{{ item.ipv }}'
protocol: '{{ item.proto }}'
notify:
- Save netfilter rules
tags: tags:
- update - config
- firewall - unbound

11
vars/main.yml Normal file
View File

@ -0,0 +1,11 @@
firewall:
- { port: 53, ipv: "v4", proto: "tcp" }
- { port: 53, ipv: "v4", proto: "udp" }
- { port: 53, ipv: "v6", proto: "tcp" }
- { port: 53, ipv: "v6", proto: "udp" }
systemd:
services:
- { name: "systemd-resolved", state: stopped }
- { name: "unbound", enabled: true, state: reloaded }
apt_packages:
- { package: "unbound", state: present }