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

myql and sqlite3 schema path/filename variable add #98

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,28 @@ pdns_lmdb_databases_locations: []
Locations of the LMDB databases that have to be created if using the
`lmdb` backend.

Locations of the mysql and sqlite3 base schema for RedHat platform
```yaml
pdns_rh_mysql_schema_file: {{}}

pdns_rh_sqlite3_schema_file: {{}}
```

Locations of the mysql and sqlite3 base schema for Debian based platform
```yaml
pdns_deb_mysql_schema_file: {{}}

pdns_deb_sqlite3_schema_file: {{}}
```

Locations of the mysql and sqlite3 base schema for ArchLinux platform
```yaml
pdns_arch_mysql_schema_file: {{}}

pdns_arch_sqlite3_schema_file: {{}}
```


## Example Playbooks

Run as a master using the bind backend (when you already have a `named.conf` file):
Expand Down
46 changes: 9 additions & 37 deletions tasks/database-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,23 @@
changed_when: False

- block:

- name: Define the PowerDNS database MySQL schema file path on RedHat < 7 and PowerDNS < 4.2.0
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns/schema.mysql.sql"
when: ansible_distribution_major_version | int < 7
and _pdns_running_version is version_compare('4.2.0', '<')

- name: Define the PowerDNS database MySQL schema file path on RedHat >= 7 or PowerDNS >= 4.2.0
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql-{{ _pdns_running_version }}/schema.mysql.sql"
when: ansible_distribution_major_version | int == 7
or _pdns_running_version is version_compare('4.2.0', '>=')

- name: Define the PowerDNS database MySQL schema file path on RedHat 8 and PowerDNS >= 4.2.0
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql"
when:
- ansible_distribution_major_version | int == 8
- _pdns_running_version is version_compare('4.2.0', '>=')

when: ansible_os_family == 'RedHat'

- block:

- name: Define the PowerDNS database MySQL schema file path on Debian
set_fact:
_pdns_mysql_schema_file: "/usr/share/dbconfig-common/data/pdns-backend-mysql/install/mysql"
when: pdns_install_repo | length == 0 and ansible_distribution_major_version | int < 10

- name: Define the PowerDNS database MySQL schema file path on Debian
set_fact:
_pdns_mysql_schema_file: "/usr/share/pdns-backend-mysql/schema/schema.mysql.sql"
when: pdns_install_repo | length == 0 and ansible_distribution_major_version | int >= 10
_pdns_mysql_schema_file: "{{ pdns_deb_mysql_schema_file }}"

when: ansible_os_family == 'Debian'

- name: Define the PowerDNS database MySQL schema file path on Debian
- block:
- name: Define the PowerDNS database MySQL schema file path on RedHat
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql"
when: pdns_install_repo | length > 0

when: ansible_os_family == 'Debian'
_pdns_mysql_schema_file: "{{ pdns_rh_mysql_schema_file }}"

when: ansible_os_family == 'RedHat'

- block:
- name: Define the PowerDNS DB schema file path on Arch Linux
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/powerdns/schema.mysql.sql"
_pdns_mysql_schema_file: "{{ pdns_arch_mysql_schema_file }}"

when: ansible_os_family == 'Archlinux'

Expand Down
26 changes: 6 additions & 20 deletions tasks/database-sqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,13 @@
with_items: "{{ pdns_sqlite_databases_locations }}"

- block:
- name: Define the PowerDNS SQLite schema file path on RedHat < 7 and PowerDNS < 4.2.0
- name: Define the PowerDNS SQLite schema file path on RedHat
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns/schema.sqlite3.sql"
when: ansible_distribution_major_version | int < 7
and _pdns_running_version is version_compare('4.2.0', '<')

- name: Define the PowerDNS SQLite schema file path on RedHat >= 7 or PowerDNS >= 4.2.0
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-sqlite-{{ _pdns_running_version }}/schema.sqlite3.sql"
when: ansible_distribution_major_version | int == 7
or _pdns_running_version is version_compare('4.2.0', '>=')

- name: Define the PowerDNS SQLite schema file path on RedHat 8 and PowerDNS >= 4.2.0
set_fact:
_pdns_mysql_schema_file: "/usr/share/doc/pdns/schema.sqlite3.sql"
when:
- ansible_distribution_major_version | int == 8
- _pdns_running_version is version_compare('4.2.0', '>=')
_pdns_sqlite3_schema_file: "{{ pdns_rh_sqlite3_schema_file }}"
when: ansible_os_family == "RedHat"

- name: Create the PowerDNS SQLite databases on RedHat
shell: "sqlite3 {{ item }} < {{ _pdns_mysql_schema_file }}"
shell: "sqlite3 {{ item }} < {{ _pdns_sqlite3_schema_file }}"
args:
creates: "{{ item }}"
with_items: "{{ pdns_sqlite_databases_locations }}"
Expand All @@ -52,7 +38,7 @@
- block:

- name: Create the PowerDNS SQLite databases on Debian
shell: "sqlite3 {{ item }} < /usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql"
shell: "sqlite3 {{ item }} < {{ pdns_deb_sqlite3_schema_file }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we'd have a separate variable name for each distro type, this is why we have the vars file that set this. I would prefer to have a pdns_sqlite3_schema_file (etc.) that are set in the vars by defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get it well you propose just two (sqlite3 and mysql schemas variables) in the defaults/main.yml file that will look like the following. Correct?

pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql"
pdns_sqlite3_schema_file: "/usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indedd, whose values are set via an underscore var from the vars/* files

args:
creates: "{{ item }}"
with_items: "{{ pdns_sqlite_databases_locations }}"
Expand All @@ -61,7 +47,7 @@

- block:
- name: Initiate the SQLite database on Arch Linux
shell: "sqlite3 {{ item }} < /usr/share/doc/powerdns/schema.sqlite3.sql"
shell: "sqlite3 {{ item }} < {{ pdns_arch_sqlite3_schema_file }}"
args:
creates: "{{ item }}"
with_items: "{{ pdns_sqlite_databases_locations }}"
Expand Down
4 changes: 4 additions & 0 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pdns_mysql_packages:
- python-pymysql
- mariadb-clients

# Default DB schema file
pdns_arch_mysql_schema_file: "/usr/share/doc/powerdns/schema.mysql.sql"
pdns_arch_sqlite3_schema_file: "/usr/share/doc/powerdns/schema.sqlite3.sql"

# Other defaults
pdns_user: powerdns
pdns_group: powerdns
4 changes: 4 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ default_pdns_backends_packages:

# The directory where the PowerDNS Authoritative Server configuration is located
default_pdns_config_dir: "/etc/powerdns"

# Default DB schema file
pdns_deb_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql"
pdns_deb_sqlite3_schema_file: "/usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql"
4 changes: 4 additions & 0 deletions vars/RedHat-8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ default_pdns_backends_packages:

# The directory where the PowerDNS Authoritative Server configuration is located
default_pdns_config_dir: "/etc/pdns"

# Default DB schema file
pdns_rh_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql"
pdns_rh_sqlite3_schema_file: "/usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql"