Skip to content

Commit

Permalink
chore: update with_* with loop keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin A committed Jun 4, 2024
1 parent 0068e56 commit 14d7758
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tasks/database-lmdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
group: "{{ pdns_group }}"
state: directory
mode: 0750
with_items: "{{ pdns_lmdb_databases_locations }}"
loop: "{{ pdns_lmdb_databases_locations }}"
11 changes: 4 additions & 7 deletions tasks/database-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
state: present
when: "item.key.split(':')[0] == 'gmysql'"
no_log: true
with_dict: "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"
loop: "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True | dict2items) }}"

- name: Grant PowerDNS access to the MySQL databases
community.mysql.mysql_user:
Expand All @@ -29,18 +29,15 @@
priv: "{{ item[0]['dbname'] }}.*:ALL"
append_privs: true
state: present
with_subelements:
- "{{ pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True) }}"
- priv_host
- skip_missing: true
loop: "{{ (pdns_backends | combine(pdns_mysql_databases_credentials, recursive=True)) | dict2items | subelements('priv_host', skip_missing=true) }}"

- name: Check if the MySQL databases are empty
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 }}"
loop: "{{ pdns_backends | dict2items }}"
register: _pdns_check_mysql_db
no_log: true
changed_when: false
Expand Down Expand Up @@ -75,4 +72,4 @@
target: "{{ pdns_mysql_schema_file_to_use }}"
no_log: true
when: "item['item']['key'].split(':')[0] == 'gmysql' and item['stdout'] == '0'"
with_items: "{{ _pdns_check_mysql_db['results'] }}"
loop: "{{ _pdns_check_mysql_db['results'] }}"
6 changes: 3 additions & 3 deletions tasks/database-sqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
group: "{{ pdns_group }}"
state: directory
mode: 0750
with_items: "{{ pdns_sqlite_databases_locations }}"
loop: "{{ pdns_sqlite_databases_locations }}"

- name: Determine location of the SQL file
ansible.builtin.shell:
Expand All @@ -44,7 +44,7 @@
ansible.builtin.shell: "sqlite3 {{ item }} < {{ pdns_sqlite_schema_file_to_use }}"
args:
creates: "{{ item }}"
with_items: "{{ pdns_sqlite_databases_locations }}"
loop: "{{ pdns_sqlite_databases_locations }}"

- name: Check the PowerDNS SQLite databases permissions
ansible.builtin.file:
Expand All @@ -53,4 +53,4 @@
group: "{{ pdns_group }}"
mode: 0640
state: file
with_items: "{{ pdns_sqlite_databases_locations }}"
loop: "{{ pdns_sqlite_databases_locations }}"
2 changes: 1 addition & 1 deletion tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
state: present
no_log: true
when: pdns_backends_packages[item.key.split(':')[0]] is defined
with_dict: "{{ pdns_backends }}"
loop: "{{ pdns_backends | dict2items }}"

0 comments on commit 14d7758

Please sign in to comment.