]> git.immae.eu Git - github/fretlink/ansible-postgresql-role.git/commitdiff
improvement: remove 'with_items' loop and use modern ansible loops
authorPaul B <paul@bonaud.fr>
Mon, 7 Jan 2019 17:01:00 +0000 (18:01 +0100)
committerPaul B <paul@bonaud.fr>
Mon, 7 Jan 2019 17:21:52 +0000 (18:21 +0100)
Ansible > 2.5 needed

meta/main.yml
tasks/main.yml
tasks/postgres-cluster.yml
tasks/postgres-pgupgrades.yml

index e0a9f498c64550f2de393254af6e7eb7e771b109..2d7ff6152419d1bf62596062629474451ed33d67 100644 (file)
@@ -4,7 +4,7 @@ galaxy_info:
   description: "Install, configure and manage PostgreSQL clusters"
   license: MIT
 
-  min_ansible_version: 2.0
+  min_ansible_version: 2.5
 
   platforms:
   - name: Ubuntu
index ad6b5bb1dba6499ceeab748bb8e99134f655ca15..2fa78839d1d2f5ce06024dd31851dfd77c041cc5 100644 (file)
   when: (postgres_clusters is not defined) or (postgres_clusters|length == 0)
 
 - include: postgres-cluster.yml
-    postgres_version={{ item.version }}
-    postgres_cluster_name={{ item.name }}
-    postgres_port={{ item.port }}
-    postgres_fsync_enabled={{ item.fsync_enabled }}
-    postgres_archive_enabled={{ item.archive_enabled }}
-    postgres_max_replication_slots={{ item.max_replication_slots | default(10) }}
-    postgres_extra_config={{ item.extra_config | default({}) }}
-    barman_directory={{ item.barman_directory | default(None) }}
-    postgres_primary={{ item.primary | default(None) }}
-    postgres_checksums={{ item.checksums | default(True) }}
-  with_items: "{{ postgres_clusters }}"
+  loop: "{{ postgres_clusters }}"
+  loop_control:
+    loop_var: postgres_cluster
   tags:
     - postgres
 
     - postgres-databases
 
 - include: postgres-pgupgrades.yml
-    postgres_dbname={{ item.dbname }}
-    postgres_pgbouncer_uri={{ item.pgbouncer_uri|default(None) }}
-    postgres_old_cluster_version={{ item.old_cluster_version }}
-    postgres_old_cluster_name={{ item.old_cluster_name }}
-    postgres_new_cluster_version={{ item.new_cluster_version }}
-    postgres_new_cluster_name={{ item.new_cluster_name }}
-    postgres_standby_server={{ item.standby_server }}
-    postgres_standby_old_cluster_name={{ item.standby_old_cluster_name|default(item.old_cluster_name) }}
-    postgres_standby_new_cluster_name={{ item.standby_new_cluster_name|default(item.new_cluster_name) }}
-  with_items: "{{ postgres_pgupgrades }}"
+  loop: "{{ postgres_pgupgrades }}"
+  loop_control:
+    loop_var: postgres_pgupgrade
   when: postgres_pgupgrades is defined
   tags:
     - postgres
index 769d1190a978af0b6dea8a0c3d6927a9b17bea38..c05298207a194ac5354fb55317424a5f9b5472f7 100644 (file)
@@ -1,3 +1,16 @@
+---
+- set_fact:
+    postgres_version: "{{ postgres_cluster.version }}"
+    postgres_cluster_name: "{{ postgres_cluster.name }}"
+    postgres_port: "{{ postgres_cluster.port }}"
+    postgres_fsync_enabled: "{{ postgres_cluster.fsync_enabled }}"
+    postgres_archive_enabled: "{{ postgres_cluster.archive_enabled }}"
+    postgres_max_replication_slots: "{{ postgres_cluster.max_replication_slots | default(10) }}"
+    postgres_extra_config: "{{ postgres_cluster.extra_config | default({}) }}"
+    barman_directory: "{{ postgres_cluster.barman_directory | default(None) }}"
+    postgres_primary: "{{ postgres_cluster.primary | default(None) }}"
+    postgres_checksums: "{{ postgres_cluster.checksums | default(True) }}"
+
 - name: Install postgresql version {{ postgres_version }}
   apt: name=postgresql-{{ postgres_version }}
   when: ansible_distribution_release != 'NA'
index a0b17b4f0f68f1e824b6a148a6b94cb82d890e25..6eb9cb7c334e24474f213d9b0e7e39ef5f9214a1 100644 (file)
@@ -1,7 +1,18 @@
 ---
+- set_fact:
+    postgres_dbname: "{{ postgres_pgupgrade.dbname }}"
+    postgres_pgbouncer_uri: "{{ postgres_pgupgrade.pgbouncer_uri|default(None) }}"
+    postgres_old_cluster_version: "{{ postgres_pgupgrade.old_cluster_version }}"
+    postgres_old_cluster_name: "{{ postgres_pgupgrade.old_cluster_name }}"
+    postgres_new_cluster_version: "{{ postgres_pgupgrade.new_cluster_version }}"
+    postgres_new_cluster_name: "{{ postgres_pgupgrade.new_cluster_name }}"
+    postgres_standby_server: "{{ postgres_pgupgrade.standby_server }}"
+    postgres_standby_old_cluster_name: "{{ postgres_pgupgrade.standby_old_cluster_name|default(postgres_pgupgrade.old_cluster_name) }}"
+    postgres_standby_new_cluster_name: "{{ postgres_pgupgrade.standby_new_cluster_name|default(postgres_pgupgrade.new_cluster_name) }}"
+
 - name: Find matching new cluster
   set_fact:
-    postgres_new_cluster: "{{ postgres_clusters|selectattr('name','equalto',postgres_new_cluster_name)|selectattr('version','equalto',postgres_new_cluster_version|float)|list|first }}"
+    postgres_new_cluster: "{{ postgres_clusters|selectattr('name','equalto',postgres_new_cluster_name)|selectattr('version','equalto', postgres_new_cluster_version|float)|list|first }}"
 
 - name: Extract database port of new matching cluster
   set_fact: