Skip to content

Commit 54ed666

Browse files
committed
fix issue with "is search" condition for ansible older then 2.9
In ansible older than version 2.9, the search filter may fail when processing a condition that search in the list. Issue vitabaks#78 fixed: TASK [patroni : Prepare PostgreSQL | make sure the postgresql config files exists] *********************************************************************************** task path: /root/postgresql_cluster/roles/patroni/tasks/main.yml:502 fatal: [192.168.102.150]: FAILED! => { "msg": "The conditional check 'ansible_os_family == \"Debian\" and postgresql_packages is not search(\"postgrespro\")' failed. The error was: Unexpected templating type error occurred on ({% if ansible_os_family == \"Debian\" and postgresql_packages is not search(\"postgrespro\") %} True {% else %} False {% endif %}): expected string or bytes-like object\n\nThe error appears to have been in '/root/postgresql_cluster/roles/patroni/tasks/main.yml': line 502, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n # patroni bootstrap failure is possible if the postgresql config files are missing\n - name: Prepare PostgreSQL | make sure the postgresql config files exists\n ^ here\n" }
1 parent a18d7ab commit 54ed666

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

roles/patroni/tasks/main.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@
379379
command: "{{ postgresql_bin_dir }}/pg_ctl start -D {{ postgresql_data_dir }}"
380380
when: pg_ctl_status_result.rc == 3 and
381381
(ansible_os_family == "RedHat" or
382-
postgresql_packages is search("postgrespro"))
382+
postgresql_packages|join(" ") is search("postgrespro"))
383383

384384
- name: Prepare PostgreSQL | check PostgreSQL is accepting connections
385385
become: true
@@ -451,7 +451,7 @@
451451
retries: 10
452452
delay: 30
453453
when: ansible_os_family == "Debian" and
454-
postgresql_packages is not search("postgrespro")
454+
postgresql_packages|join(" ") is not search("postgrespro")
455455

456456
# "RedHat" or PostgresPro
457457
- name: Prepare PostgreSQL | stop PostgreSQL (will be managed by patroni)
@@ -463,7 +463,7 @@
463463
retries: 30
464464
delay: 10
465465
when: ansible_os_family == "RedHat" or
466-
postgresql_packages is search("postgrespro")
466+
postgresql_packages|join(" ") is search("postgrespro")
467467

468468
- name: Prepare PostgreSQL | check PostgreSQL is stopped
469469
become: true
@@ -504,7 +504,7 @@
504504
path: "{{ postgresql_conf_dir }}/postgresql.conf"
505505
register: postgresql_conf_file
506506
when: ansible_os_family == "Debian" and
507-
postgresql_packages is not search("postgrespro")
507+
postgresql_packages|join(" ") is not search("postgrespro")
508508

509509
- name: Prepare PostgreSQL | generate default postgresql config files
510510
become: true
@@ -518,7 +518,7 @@
518518
register: pg_createcluster_result
519519
failed_when: pg_createcluster_result.rc != 0
520520
when: (ansible_os_family == "Debian" and
521-
postgresql_packages is not search("postgrespro")) and
521+
postgresql_packages|join(" ") is not search("postgrespro")) and
522522
not postgresql_conf_file.stat.exists
523523

524524
- name: Prepare PostgreSQL | make sure the data directory "{{ postgresql_data_dir }}" is empty on Master
@@ -625,7 +625,7 @@
625625

626626
- name: Start PostgreSQL for Recovery # RedHat or PostgresPro
627627
command: "{{ postgresql_bin_dir }}/pg_ctl start -D {{ postgresql_data_dir }} -o '-c hot_standby=off'"
628-
when: (ansible_os_family == "RedHat" or postgresql_packages is search("postgrespro")) and
628+
when: (ansible_os_family == "RedHat" or postgresql_packages|join(" ") is search("postgrespro")) and
629629
(is_master == "true" or
630630
(is_master != "true" and 'pgbackrest' in patroni_create_replica_methods))
631631

@@ -661,7 +661,7 @@
661661
until: stop_result.rc == 0
662662
retries: 10
663663
delay: 10
664-
when: (ansible_os_family == "RedHat" or postgresql_packages is search("postgrespro")) and
664+
when: (ansible_os_family == "RedHat" or postgresql_packages|join(" ") is search("postgrespro")) and
665665
(pg_ctl_status_result.rc is defined and pg_ctl_status_result.rc != 3)
666666
when: patroni_cluster_bootstrap_method == "pgbackrest"
667667
become: true
@@ -895,7 +895,7 @@
895895
enabled: false
896896
daemon_reload: true
897897
when: ansible_os_family == "Debian" and
898-
postgresql_packages is not search("postgrespro")
898+
postgresql_packages|join(" ") is not search("postgrespro")
899899
tags: patroni, postgresql_disable
900900

901901
# "RedHat"
@@ -905,7 +905,7 @@
905905
enabled: false
906906
daemon_reload: true
907907
when: ansible_os_family == "RedHat" and
908-
postgresql_packages is not search("postgrespro")
908+
postgresql_packages|join(" ") is not search("postgrespro")
909909
tags: patroni, postgresql_disable
910910

911911
# PostgresPro
@@ -914,7 +914,7 @@
914914
name: "postgrespro-std-{{ postgresql_version }}"
915915
enabled: false
916916
daemon_reload: true
917-
when: postgresql_packages is search("postgrespro-std")
917+
when: postgresql_packages|join(" ") is search("postgrespro-std")
918918
tags: patroni, postgresql_disable
919919

920920
# PATRONICTL_CONFIG_FILE (patroni v1.6.1 and higher)

roles/pgbouncer/tasks/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
state: link
6363
when: not pgbouncer_bin.stat.exists
6464
when: ansible_os_family == "RedHat" and
65-
postgresql_packages is search("postgrespro")
65+
postgresql_packages|join(" ") is search("postgrespro")
6666
tags: pgbouncer_service, pgbouncer
6767

6868
- name: Enable log rotation with logrotate

0 commit comments

Comments
 (0)