--- - name: Install the MySQL dependencies on RedHat package: name: "{{ item }}" state: present with_items: - mysql - MySQL-python when: ansible_facts.os_family == 'RedHat' - name: Install the MySQL dependencies on Debian package: name: "{{ item }}" state: present with_items: - mysql-client - python-mysqldb when: ansible_facts.os_family == 'Debian' - name: Create the PowerDNS Authoritative Server MySQL databases 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'" with_dict: "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}" - name: Grant the PowerDNS Authoritative Server access to the MySQL databases mysql_user: login_user: "{{ item[0]['priv_user'] }}" login_password: "{{ item[0]['priv_password'] }}" login_host: "{{ item[0]['host'] }}" login_port: "{{ item[0]['port'] | default('3306') }}" name: "{{ item[0]['user'] }}" password: "{{ item[0]['password'] }}" host: "{{ item[1] }}" priv: "{{ item[0]['dbname'] }}.*:ALL" append_privs: yes state: present with_subelements: - "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}" - priv_host - skip_missing: yes - name: Check if the PowerDNS Authoritative Server 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 --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 changed_when: False - name: Define the PowerDNS Authoritative Server database MySQL schema file path on RedHat < 7 set_fact: _pdns_mysql_schema_file: "/usr/share/doc/pdns/schema.mysql.sql" when: ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_major_version | int < 7 - name: Define the PowerDNS Authoritative Server database MySQL schema file path on RedHat >= 7 set_fact: _pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql-{{ _pdns_running_version | regex_replace('-rc[\\d]*$', '') }}/schema.mysql.sql" when: ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_major_version | int >= 7 - name: Define the PowerDNS Authoritative Server database MySQL schema file path on Debian set_fact: _pdns_mysql_schema_file: "/usr/share/dbconfig-common/data/pdns-backend-mysql/install/mysql" when: ansible_facts.os_family == 'Debian' and pdns_install_repo == '' - name: Define the PowerDNS Authoritative Server database MySQL schema file path on Debian set_fact: _pdns_mysql_schema_file: "/usr/share/doc/pdns-backend-mysql/schema.mysql.sql" when: ansible_facts.os_family == 'Debian' and pdns_install_repo != '' - name: Import the PowerDNS Authoritative Server MySQL schema 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 }}" when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0'" with_items: "{{ _pdns_check_mysql_db['results'] }}"