๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/ns/tasks/install.yml

138 lines
3.2 KiB

2 years ago
- name: install powerdns and dependencies
include_tasks: tasks/install_packages.yml
vars:
package:
- pdns
- alpine: pdns-openrc
- pdns-backend-pgsql
- pdns-doc
- name: create user and group
include_tasks: tasks/create_user.yml
vars:
user:
name: "{{ pdns_user }}"
group: "{{ pdns_group }}"
- name: create pdns config directories
file:
path: "{{ item }}"
state: directory
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
mode: 0750
loop:
- "{{ pdns_dir }}"
- "{{ pdns_custom_dir }}"
- name: template pdns config
template:
src: custom.j2
dest: "{{ pdns_custom_dir }}/custom.conf"
force: yes
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
mode: 0640
- name: add include-dir to default pdns config
lineinfile:
path: "{{ pdns_dir }}/pdns.conf"
line: "include-dir={{ pdns_custom_dir }}"
create: yes
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
mode: 0640
- name: remove unwanted lines from default pdns config
lineinfile:
path: "{{ pdns_dir }}/pdns.conf"
regex: '^\s*{{ item }}\s*='
state: absent
loop:
- use-logfile
- wildcards
- name: populate database
include_tasks: populate_db.yml
- name: add internal zone
command:
cmd: "pdnsutil create-zone {{ int_tld | quote }} {{ (inventory_hostname ~ '.' ~ int_tld) | quote }}"
register: res
changed_when: (res.rc == 0) and ("Creating empty zone" in res.stderr)
failed_when: (res.rc != 0) and ("exists already" not in res.stderr)
- name: add NS records for internal zone
include_tasks: add_record.yml
vars:
item: { 'name': '@', 'type': 'NS', value: "{{ inventory_hostname ~ '.' ~ int_tld }}" }
- name: add branch zones
command:
cmd: "pdnsutil create-zone {{ item ~ '.' ~ int_tld | quote }} {{ (inventory_hostname ~ '.' ~ int_tld) | quote }}"
register: res
changed_when: (res.rc == 0) and ("Creating empty zone" in res.stderr)
failed_when: (res.rc != 0) and ("exists already" not in res.stderr)
loop:
"{{ int_branches | default([]) }}"
- name: prepare list of NS records for branches
set_fact:
ns_subs: "{{ ns_subs | default([]) + [{ 'zone': item, 'name': '@', 'type': 'NS', 'value': inventory_hostname ~ '.' ~ int_tld }] }}"
loop: "{{ int_branches | default([]) }}"
- name: add NS records for branch zones
include_tasks: add_record.yml
vars:
ns_records: "{{ ns_subs | default([]) }}"
- name: prepare list of NS delegated records for root zone
set_fact:
ns_delegated: "{{ ns_delegated | default([]) + [{ 'zone': 'root', 'name': item, 'type': 'NS', 'value': inventory_hostname ~ '.' ~ int_tld }] }}"
loop: "{{ int_branches | default([]) }}"
- name: add NS delegated records for root zone
include_tasks: add_record.yml
vars:
ns_records: "{{ ns_delegated | default([]) }}"
- name: rectify all zones
command:
cmd: pdnsutil rectify-all-zones
register: res
changed_when: false
failed_when: res.rc != 0
- name: flush handlers
meta: flush_handlers
- name: add ns directories to backup plan
include_tasks: tasks/add_backup.yml
vars:
backup_items:
- "{{ pdns_dir }}"
- "{{ pdns_custom_dir }}"
- name: enable and start powerdns
service:
name: pdns
state: started
enabled: yes