Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit f95c93c

Browse files
Merge pull request #12 from amarao/better_database_handling
Create/delete database no longer generate 'changed' when nessessary
2 parents ef73811 + 44083d8 commit f95c93c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tasks/config_db.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
---
2+
- name: Gather list of existing databases
3+
command: "clickhouse-client -h localhost -q 'show databases'"
4+
changed_when: False
5+
register: existing_databases
6+
tags: [config_db]
7+
18
- name: Config | Delete database config
29
command: "clickhouse-client -h localhost -q 'DROP DATABASE IF EXISTS `{{ item.name }}`'"
310
with_items: "{{ clickhouse_dbs }}"
4-
when: item.state is defined and item.state == 'absent'
11+
when: item.state is defined and item.state == 'absent' and item.name in existing_databases.stdout.lines_lines
512
tags: [config_db]
613

714
- name: Config | Create database config
815
command: "clickhouse-client -h localhost -q 'CREATE DATABASE IF NOT EXISTS `{{ item.name }}`'"
916
with_items: "{{ clickhouse_dbs }}"
10-
when: item.state is undefined or item.state == 'present'
11-
tags: [config_db]
17+
when: (item.state is undefined or item.state == 'present') and item.name not in existing_databases.stdout_lines
18+
tags: [config_db]

0 commit comments

Comments
 (0)