diff --git a/README.md b/README.md index 03ff7a1..4e8ca11 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,14 @@ 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. +When set, this value is used and they are not automatically detected. +```yaml +pdns_mysql_schema_file: '' + +pdns_sqlite3_schema_file: '' +``` + ## Example Playbooks Run as a master using the bind backend (when you already have a `named.conf` file): diff --git a/defaults/main.yml b/defaults/main.yml index 5b987fd..1d72c30 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -146,3 +146,11 @@ pdns_sqlite_databases_locations: [] # in the given locations. # NOTE: Requries lmdb backend to be installed on the machine. pdns_lmdb_databases_locations: [] + +# Override the schema used to initialize the MySQL database +# By default, this role tries to detect the correct file +pdns_mysql_schema_file: "" + +# Override the schema used to initialize the SQLite database +# By default, this role tries to detect the correct file +pdns_sqlite_schema_file: "" diff --git a/tasks/database-mysql.yml b/tasks/database-mysql.yml index 512c0cc..73c5e65 100644 --- a/tasks/database-mysql.yml +++ b/tasks/database-mysql.yml @@ -43,54 +43,24 @@ register: _pdns_check_mysql_db 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 - - - name: Define the PowerDNS database MySQL schema file path on Debian - 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' - -- 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" - - when: ansible_os_family == 'Archlinux' +- name: Determine location of the SQL file + 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; do + if [ -f $p ]; then + echo $p + exit 0 + fi + done + echo "Can't determine path to MySQL schema">&2 + exit 1 + changed_when: false + register: pdns_mysql_schema_file_detected + when: pdns_mysql_schema_file | length == 0 + +- name: Set the schema file variable + 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: @@ -100,6 +70,6 @@ login_port: "{{ item['item']['port'] | default('3306') }}" name: "{{ item.item['value']['dbname'] }}" state: import - target: "{{ _pdns_mysql_schema_file }}" + target: "{{ pdns_mysql_schema_file_to_use }}" when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0'" with_items: "{{ _pdns_check_mysql_db['results'] }}" diff --git a/tasks/database-sqlite3.yml b/tasks/database-sqlite3.yml index d74ff03..edbd89d 100644 --- a/tasks/database-sqlite3.yml +++ b/tasks/database-sqlite3.yml @@ -21,52 +21,30 @@ mode: 0750 with_items: "{{ pdns_sqlite_databases_locations }}" -- block: - - name: Define the PowerDNS SQLite schema file path on RedHat < 7 and PowerDNS < 4.2.0 - 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', '>=') - - - name: Create the PowerDNS SQLite databases on RedHat - shell: "sqlite3 {{ item }} < {{ _pdns_mysql_schema_file }}" - args: - creates: "{{ item }}" - with_items: "{{ pdns_sqlite_databases_locations }}" - - when: ansible_os_family == "RedHat" - -- block: - - - name: Create the PowerDNS SQLite databases on Debian - shell: "sqlite3 {{ item }} < /usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql" - args: - creates: "{{ item }}" - with_items: "{{ pdns_sqlite_databases_locations }}" - - when: ansible_os_family == "Debian" - -- block: - - name: Initiate the SQLite database on Arch Linux - shell: "sqlite3 {{ item }} < /usr/share/doc/powerdns/schema.sqlite3.sql" - args: - creates: "{{ item }}" - with_items: "{{ pdns_sqlite_databases_locations }}" - - when: ansible_os_family == "Archlinux" +- name: Determine location of the SQL file + 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 + echo $p + exit 0 + fi + done + echo "Can't determine path to SQLite schema">&2 + exit 1 + changed_when: false + register: pdns_sqlite_schema_file_detected + when: pdns_sqlite_schema_file | length == 0 + +- name: Set the schema file variable + 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 }}" + args: + creates: "{{ item }}" + with_items: "{{ pdns_sqlite_databases_locations }}" - name: Check the PowerDNS SQLite databases permissions file: