vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on "Patroni" and DCS "etcd" or "consul"). Automating with Ansible.
MIT License
1.27k stars 340 forks source link

Problem with one of the playbook tasks #563

Closed Anatr0p closed 3 months ago

Anatr0p commented 3 months ago

Hi there, Vitaliy. Appreciate your work, amazing automation complex)

I'm using your playbooks a couple month already, but now I faced an issue with task: "Prepare PostgreSQL | make sure the data directory "/var/lib/postgresql/15/main" is empty" I'm using the latest repo of yours (master branch, all updates as for 29 Jan 2024 - today)

Now I'm testing scheme B, so no haproxy, no consul So its etcd as DCS, vip-manager and pgbouncer, PostgreSQL 15 3 nodes, Debian 11, totally identical machines, clean installation on official Debian ISO, no any additional software, etc

When deploy playbook being executed, script checks for 15/main dir in postgresql dir (it all default for Debian as mentioned in task name". I didnt change patroni main.yml role config

This error popping up on replicas only, master passed just OK When I try to check the dir (sudo ls -la /var/lib/postgresql/15/main) - it is totally empty on both replicas

Can you please suggest any possible workarounds? Very appreciate your time that u can spend to help me with it

Anatr0p commented 3 months ago

Here is the error itself (identical for both replica nodes)

fatal: [10.*.*.*]: FAILED! => {"msg": "The conditional check '(is_master | bool and patroni_cluster_bootstrap_method != \"pgbackrest\") or (not is_master | bool and ('pgbackrest' not in patroni_create_replica_methods or new_node | default(false) | bool))' failed. The error was: error while evaluating conditional ((is_master | bool and patroni_cluster_bootstrap_method != \"pgbackrest\") or (not is_master | bool and ('pgbackrest' not in patroni_create_replica_methods or new_node | default(false) | bool))): 'is_master' is undefined. 'is_master' is undefined\n\nThe error appears to be in '/etc/ansible/postgresql_cluster/roles/patroni/tasks/main.yml': line 460, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    # to be able to use the '--delta restore' option.\n    - name: Prepare PostgreSQL | make sure the data directory \"{{ postgresql_data_dir }}\" is empty\n      ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}

And here is the task (it is untouched):

- name: Prepare PostgreSQL | make sure the data directory "{{ postgresql_data_dir }}" is empty
      ansible.builtin.file:
        path: "{{ postgresql_data_dir }}"
        state: "{{ item }}"
        owner: postgres
        group: postgres
        mode: "0700"
      loop:
        - absent
        - directory
      when: (is_master | bool and patroni_cluster_bootstrap_method != "pgbackrest")
            or (not is_master | bool and ('pgbackrest' not in patroni_create_replica_methods or new_node | default(false) | bool))
Anatr0p commented 3 months ago

And, of course, there is no pgbackrest used in my setup, just default basebackup for now

vitabaks commented 3 months ago

'is_master' is undefined

Have you deleted the group_vars directory? The default variable "is_master" is defined there.

Please attach the archive of your postgresql_cluster catalog for analysis.

Anatr0p commented 3 months ago

'is_master' is undefined

Have you deleted the group_vars directory? The default variable "is_master" is defined there.

Please attach the archive of your postgresql_cluster catalog for analysis.

Damn, you are totally right, thank u a lot, forgot about that configuration. I re-pulled the whole repo and forget about it Thanks again!