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

Allow mysql-specific tasks to run based when using a gmysql backend, not on pdns_mysql_databases_credentials #186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# By default, no PowerDNS Authoritative Server repository will be configured by the role
pdns_install_repo: ""

# To install tje PowerDNS Authoritative Server from the 'master' official repository
# To install the PowerDNS Authoritative Server from the 'master' official repository
# use the following playbook snippet
# - hosts: all
# roles:
Expand Down Expand Up @@ -147,6 +147,10 @@ pdns_sqlite_databases_locations: []
# NOTE: Requries lmdb backend to be installed on the machine.
pdns_lmdb_databases_locations: []

# By default, we'll load the MySQL default schema. Set this to Falso to disable loading the schema
# (e.g. when importing your own dump later on)
pdns_mysql_schema_load: true

# Override the schema used to initialize the MySQL database
# By default, this role tries to detect the correct file
pdns_mysql_schema_file: ""
Expand Down
11 changes: 7 additions & 4 deletions tasks/database-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
login_port: "{{ item['value']['port'] | default('3306') }}"
name: "{{ item['value']['dbname'] }}"
state: present
when: "item.key.split(':')[0] == 'gmysql'"
when: "item.key.split(':')[0] == 'gmysql' and pdns_mysql_databases_credentials"
no_log: True
with_dict: "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"

Expand All @@ -29,15 +29,17 @@
priv: "{{ item[0]['dbname'] }}.*:ALL"
append_privs: yes
state: present
when: pdns_mysql_databases_credentials
with_subelements:
- "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"
- priv_host
- skip_missing: yes

# TODO: add support for file socket connections instead of host/port combos
- name: Check if the MySQL databases are empty
command: >
mysql --user="{{ item['value']['user'] }}" --password="{{ item['value']['password'] }}"
--host="{{ item['value']['host'] }}" --port "{{ item['value']['port'] | default('3306') }}" --batch --skip-column-names
--host="{{ item['value']['host'] | default('localhost') }}" --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 }}"
Expand All @@ -64,15 +66,16 @@
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 %}"

# TODO: add support for file socket connections instead of host/port combos
- name: Import the PowerDNS MySQL schema
mysql_db:
login_user: "{{ item['item']['value']['user'] }}"
login_password: "{{ item['item']['value']['password'] }}"
login_host: "{{ item['item']['value']['host'] }}"
login_host: "{{ item['item']['value']['host'] | default('localhost') }}"
login_port: "{{ item['item']['port'] | default('3306') }}"
name: "{{ item.item['value']['dbname'] }}"
state: import
target: "{{ pdns_mysql_schema_file_to_use }}"
no_log: True
when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0'"
when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0' and pdns_mysql_schema_load"
with_items: "{{ _pdns_check_mysql_db['results'] }}"
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- config

- include_tasks: database-mysql.yml
when: "pdns_mysql_databases_credentials | length > 0"
when: "'gmysql' in pdns_backends"
tags:
- db
- mysql
Expand Down
2 changes: 1 addition & 1 deletion tasks/selinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: pdns_can_network_connect_db
state: yes
persistent: yes
when: "pdns_mysql_databases_credentials | length > 0"
when: "'gmysql' in pdns_backends"

- name: allow pdns to bind to udp high ports
seport:
Expand Down