Skip to content

Commit

Permalink
feat: Update Ansible module names to official documentation defaults …
Browse files Browse the repository at this point in the history
…and ajust booleans
  • Loading branch information
Robin A committed Jun 4, 2024
1 parent a5897e6 commit 0068e56
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 65 deletions.
16 changes: 8 additions & 8 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
- block:

- name: Ensure the override directory exists (systemd)
file:
ansible.builtin.file:
name: "/etc/systemd/system/{{ pdns_service_name }}.service.d"
state: directory
owner: root
group: root

- name: Override the PowerDNS Authoritative Server unit (systemd)
template:
ansible.builtin.template:
src: "override-service.systemd.conf.j2"
dest: "/etc/systemd/system/{{ pdns_service_name }}.service.d/override.conf"
owner: root
Expand All @@ -19,23 +19,23 @@
when: pdns_service_overrides | length > 0

- name: Reload systemd
systemd:
daemon_reload: yes
ansible.builtin.systemd:
daemon_reload: true
when: not pdns_disable_handlers
and _pdns_override_unit.changed

when: ansible_service_mgr == "systemd"

- name: Ensure that the PowerDNS configuration directory exists
file:
ansible.builtin.file:
name: "{{ pdns_config_dir }}"
state: directory
owner: "{{ pdns_file_owner }}"
group: "{{ pdns_file_group }}"
mode: 0750

- name: Generate the PowerDNS configuration
template:
ansible.builtin.template:
src: pdns.conf.j2
dest: "{{ pdns_config_dir }}/{{ pdns_config_file }}"
owner: "{{ pdns_file_owner }}"
Expand All @@ -45,7 +45,7 @@
no_log: true

- name: Ensure that the PowerDNS 'include-dir' directory exists
file:
ansible.builtin.file:
name: "{{ pdns_config['include-dir'] }}"
state: directory
owner: "{{ pdns_file_owner }}"
Expand All @@ -54,7 +54,7 @@
when: "pdns_config['include-dir'] is defined"

- name: Restart PowerDNS
service:
ansible.builtin.service:
name: "{{ pdns_service_name }}"
state: restarted
sleep: 1
Expand Down
2 changes: 1 addition & 1 deletion tasks/database-lmdb.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Ensure that the directories containing the PowerDNS LMDB databases exist
file:
ansible.builtin.file:
name: "{{ item | dirname }}"
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
Expand Down
26 changes: 13 additions & 13 deletions tasks/database-mysql.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---

- name: Install the MySQL dependencies
package:
ansible.builtin.package:
name: "{{ pdns_mysql_packages }}"
state: present

- name: Create the PowerDNS MySQL databases
mysql_db:
community.mysql.mysql_db:
login_user: "{{ item['value']['priv_user'] }}"
login_password: "{{ item['value']['priv_password'] }}"
login_host: "{{ item['value']['host'] }}"
login_port: "{{ item['value']['port'] | default('3306') }}"
name: "{{ item['value']['dbname'] }}"
state: present
when: "item.key.split(':')[0] == 'gmysql'"
no_log: True
no_log: true
with_dict: "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"

- name: Grant PowerDNS access to the MySQL databases
mysql_user:
community.mysql.mysql_user:
login_user: "{{ item[0]['priv_user'] }}"
login_password: "{{ item[0]['priv_password'] }}"
login_host: "{{ item[0]['host'] }}"
Expand All @@ -27,26 +27,26 @@
password: "{{ item[0]['password'] }}"
host: "{{ item[1] }}"
priv: "{{ item[0]['dbname'] }}.*:ALL"
append_privs: yes
append_privs: true
state: present
with_subelements:
- "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"
- priv_host
- skip_missing: yes
- skip_missing: true

- name: Check if the MySQL databases are empty
command: >
ansible.builtin.command: >
mysql --user="{{ item['value']['user'] }}" --password="{{ item['value']['password'] }}"
--host="{{ item['value']['host'] }}" --port "{{ item['value']['port'] | default('3306') }}" --batch --skip-column-names
--execute="SELECT COUNT(DISTINCT table_name) FROM information_schema.columns WHERE table_schema = '{{ item['value']['dbname'] }}'"
when: item.key.split(':')[0] == 'gmysql'
with_dict: "{{ pdns_backends }}"
register: _pdns_check_mysql_db
no_log: True
changed_when: False
no_log: true
changed_when: false

- name: Determine location of the SQL file
shell:
ansible.builtin.shell:
cmd: |
for p in /usr/share/doc/pdns-backend-mysql-{{ _pdns_running_version }}/schema.mysql.sql /usr/share/doc/pdns-backend-mysql/schema.mysql.sql /usr/share/pdns-backend-mysql/schema/schema.mysql.sql /usr/share/dbconfig-common/data/pdns-backend-mysql/install/mysql /usr/share/doc/powerdns/schema.mysql.sql /usr/share/doc/pdns/schema.mysql.sql; do
if [ -f $p ]; then
Expand All @@ -61,18 +61,18 @@
when: pdns_mysql_schema_file | length == 0

- name: Set the schema file variable
set_fact:
ansible.builtin.set_fact:
pdns_mysql_schema_file_to_use: "{% if pdns_mysql_schema_file | length == 0 %}{{ pdns_mysql_schema_file_detected.stdout }}{% else %}{{ pdns_mysql_schema_file }}{% endif %}"

- name: Import the PowerDNS MySQL schema
mysql_db:
community.mysql.mysql_db:
login_user: "{{ item['item']['value']['user'] }}"
login_password: "{{ item['item']['value']['password'] }}"
login_host: "{{ item['item']['value']['host'] }}"
login_port: "{{ item['item']['port'] | default('3306') }}"
name: "{{ item.item['value']['dbname'] }}"
state: import
target: "{{ pdns_mysql_schema_file_to_use }}"
no_log: True
no_log: true
when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0'"
with_items: "{{ _pdns_check_mysql_db['results'] }}"
14 changes: 7 additions & 7 deletions tasks/database-sqlite3.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---

- name: Install the SQLite dependencies on RedHat
package:
ansible.builtin.package:
name: sqlite
state: present
when: ansible_os_family == 'RedHat'

- name: Install the SQLite dependencies on Debian
package:
ansible.builtin.package:
name: sqlite3
state: present
when: ansible_os_family == 'Debian'

- name: Ensure that the directories containing the PowerDNS SQLite databases exist
file:
ansible.builtin.file:
name: "{{ item | dirname }}"
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
Expand All @@ -22,7 +22,7 @@
with_items: "{{ pdns_sqlite_databases_locations }}"

- name: Determine location of the SQL file
shell:
ansible.builtin.shell:
cmd: |
for p in /usr/share/doc/pdns-backend-sqlite-{{ _pdns_running_version }}/schema.sql /usr/share/doc/pdns-backend-sqlite-{{ _pdns_running_version }}/schema.sqlite3.sql /usr/share/doc/pdns/schema.sqlite3.sql /usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql /usr/share/doc/pdns-backend-sqlite/schema.sqlite3.sql /usr/share/doc/powerdns/schema.sqlite3.sql; do
if [ -f $p ]; then
Expand All @@ -37,17 +37,17 @@
when: pdns_sqlite_schema_file | length == 0

- name: Set the schema file variable
set_fact:
ansible.builtin.set_fact:
pdns_sqlite_schema_file_to_use: "{% if pdns_sqlite_schema_file | length == 0 %}{{ pdns_sqlite_schema_file_detected.stdout }}{% else %}{{ pdns_sqlite_schema_file }}{% endif %}"

- name: Create the PowerDNS SQLite databases
shell: "sqlite3 {{ item }} < {{ pdns_sqlite_schema_file_to_use }}"
ansible.builtin.shell: "sqlite3 {{ item }} < {{ pdns_sqlite_schema_file_to_use }}"
args:
creates: "{{ item }}"
with_items: "{{ pdns_sqlite_databases_locations }}"

- name: Check the PowerDNS SQLite databases permissions
file:
ansible.builtin.file:
name: "{{ item }}"
owner: "{{ pdns_user }}"
group: "{{ pdns_group }}"
Expand Down
6 changes: 3 additions & 3 deletions tasks/inspect.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

- name: Obtain the version of the running PowerDNS instance
shell: |
ansible.builtin.shell: |
pdns_server --version 2>&1 | awk '/PowerDNS Authoritative/{print $7}'
register: _pdns_version
check_mode: no
changed_when: False
changed_when: false

- name: Export the running PowerDNS instance version to a variable
set_fact:
ansible.builtin.set_fact:
_pdns_running_version: "{{ _pdns_version['stdout'] | regex_replace('-[.\\d\\w]+$', '') }}"
12 changes: 6 additions & 6 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@
- block:

- name: Prefix the PowerDNS version with the correct separator on RedHat
set_fact:
ansible.builtin.set_fact:
_pdns_package_version: "-{{ pdns_package_version }}"
when: ansible_os_family == 'RedHat'

- name: Prefix the PowerDNS version with the correct separator on Debian
set_fact:
ansible.builtin.set_fact:
_pdns_package_version: "={{ pdns_package_version }}"
when: ansible_os_family == 'Debian'

when: "pdns_package_version | length > 0"

- name: Install PowerDNS
package:
ansible.builtin.package:
name: "{{ pdns_package_name }}{{ _pdns_package_version | default('') }}"
state: present

- name: Install PowerDNS debug symbols
package:
ansible.builtin.package:
name: "{{ pdns_debug_symbols_package_name }}{{ _pdns_package_version | default('') }}"
state: present
when: pdns_install_debug_symbols_package

- name: Install PowerDNS backends
package:
ansible.builtin.package:
name: "{{ pdns_backends_packages[item.key.split(':')[0]] }}{{ _pdns_package_version | default('') }}"
state: present
no_log: True
no_log: true
when: pdns_backends_packages[item.key.split(':')[0]] is defined
with_dict: "{{ pdns_backends }}"
20 changes: 10 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: Include OS-specific variables
include_vars: "{{ item }}"
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution }}.yml"
Expand All @@ -10,54 +10,54 @@
tags:
- always

- include_tasks: "repo-{{ ansible_os_family }}.yml"
- ansible.builtin.include_tasks: "repo-{{ ansible_os_family }}.yml"
when: "pdns_install_repo | length > 0"
tags:
- install
- repository

- include_tasks: install.yml
- ansible.builtin.include_tasks: install.yml
tags:
- install

- include_tasks: inspect.yml
- ansible.builtin.include_tasks: inspect.yml
tags:
- db
- mysql
- sqlite
- config

- include_tasks: database-mysql.yml
- ansible.builtin.include_tasks: database-mysql.yml
when: "pdns_mysql_databases_credentials | length > 0"
tags:
- db
- mysql

- include_tasks: database-sqlite3.yml
- ansible.builtin.include_tasks: database-sqlite3.yml
when: "pdns_sqlite_databases_locations | length > 0"
tags:
- db
- sqlite

- include_tasks: database-lmdb.yml
- ansible.builtin.include_tasks: database-lmdb.yml
when: "pdns_lmdb_databases_locations | length > 0"
tags:
- db
- lmdb

- include_tasks: configure.yml
- ansible.builtin.include_tasks: configure.yml
tags:
- config

- include_tasks: selinux.yml
- ansible.builtin.include_tasks: selinux.yml
when: ansible_selinux is defined and ansible_selinux.status == 'enabled'
tags:
- selinux
- config

- name: Start and enable the PowerDNS service
throttle: 1
service:
ansible.builtin.service:
name: "{{ pdns_service_name }}"
state: "{{ pdns_service_state }}"
enabled: "{{ pdns_service_enabled }}"
Expand Down
12 changes: 6 additions & 6 deletions tasks/repo-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
state: present

- name: Import the PowerDNS APT Repository key from URL
apt_key:
ansible.builtin.apt_key:
url: "{{ pdns_install_repo['gpg_key'] }}"
id: "{{ pdns_install_repo['gpg_key_id'] | default('') }}"
state: present
when: pdns_install_repo['gpg_key'] is regex("^[a-z]{3,}://")
register: _pdns_apt_key

- name: Import the PowerDNS APT Repository key from File
apt_key:
ansible.builtin.apt_key:
data: "{{ lookup('file', pdns_install_repo['gpg_key']) }}"
id: "{{ pdns_install_repo['gpg_key_id'] | default('') }}"
state: present
when: not pdns_install_repo['gpg_key'] is regex("^[a-z]{3,}://")
register: _pdns_apt_key

- name: Add the PowerDNS APT Repository
apt_repository:
ansible.builtin.apt_repository:
filename: "{{ pdns_install_repo['name'] }}"
repo: "{{ pdns_install_repo['apt_repo'] }}"
state: present
register: _pdns_apt_repo

- name: Update the APT cache
apt:
update_cache: yes
ansible.builtin.apt:
update_cache: true
when: "_pdns_apt_key.changed or _pdns_apt_repo.changed"

- name: Pin the PowerDNS APT Repository
template:
ansible.builtin.template:
src: pdns.pin.j2
dest: /etc/apt/preferences.d/pdns
owner: root
Expand Down
Loading

0 comments on commit 0068e56

Please sign in to comment.