vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on Patroni). Automating with Ansible.
https://postgresql-cluster.org
MIT License
1.69k stars 411 forks source link

ansible-playbook add_pgnode.yml #414

Closed fatmaAliGamal closed 1 year ago

fatmaAliGamal commented 1 year ago

run :: ansible-playbook add_pgnode.yml

hosts.ini
---------
[etcd_cluster]
10.0.4.71 ansible_host=44.204.70.117 
10.0.4.158 ansible_host=18.208.106.130 
10.0.5.87 ansible_host=3.80.94.238 
[balancers]
10.0.4.71 ansible_host=44.204.70.117 
10.0.4.158 ansible_host=18.208.106.130 
10.0.5.87 ansible_host=3.80.94.238 
[pgbackrest]
10.0.4.71 ansible_host=44.204.70.117 
10.0.4.158 ansible_host=18.208.106.130 
10.0.5.87 ansible_host=3.80.94.238 
[master]
10.0.4.71 ansible_host=44.204.70.117 postgresql_exists='true'
[replica]
10.0.4.158 ansible_host=18.208.106.130 postgresql_exists='true'
10.0.5.87 ansible_host=3.80.94.238 postgresql_exists='true'
10.0.4.119 ansible_host=54.90.196.77 postgresql_exists=false new_node=true
[postgres_cluster:children]
master
replica
[all:vars]
ansible_connection='ssh'
ansible_ssh_port='22'
ansible_ssh_user=ubuntu
ansible_ssh_private_key_file=./postgres-db-key-test
[pgbackrest:vars]
ansible_connection='ssh'
ansible_ssh_port='22'
ansible_ssh_user=ubuntu
ansible_ssh_private_key_file=./postgres-db-key-test

error:

TASK [pgbouncer : Copy pgbouncer.ini and userlist.txt conf files to replica] ****
changed: [10.0.4.119] => (item=pgbouncer.ini)
changed: [10.0.4.119] => (item=userlist.txt)

TASK [pgbouncer : Remove pgbouncer.ini and userlist.txt conf files from localhost] ***
failed: [10.0.4.119 -> localhost] (item=pgbouncer.ini) => {"ansible_loop_var": "item", "changed": false, "item": "pgbouncer.ini", "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
failed: [10.0.4.119 -> localhost] (item=userlist.txt) => {"ansible_loop_var": "item", "changed": false, "item": "userlist.txt", "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

failed: [10.0.4.119 -> localhost] (item=userlist.txt) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "userlist.txt",
    "module_stderr": "sudo: a password is required\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
vitabaks commented 1 year ago

@fatmaAliGamal Thank you for raising this issue.

Based on the error message you've provided, it seems the task "Remove pgbouncer.ini and userlist.txt conf files from localhost" might be encountering an issue due to the Ansible playbook trying to escalate privileges when it's not necessary.

To resolve this, we suggest setting become: false in this task. This change should inform Ansible that privilege escalation is not required to execute this specific task. The code would look as follows:

- name: Remove pgbouncer.ini and userlist.txt conf files from localhost
  run_once: true
  become: false
  file:
    path: "files/{{ item }}"
    state: absent
  loop:
    - pgbouncer.ini
    - userlist.txt
  delegate_to: localhost

Could you please implement this change in your branch and test if it resolves the problem? We would appreciate your feedback on this proposed solution.

fatmaAliGamal commented 1 year ago

this is correct solution and you need to add become: false

vitabaks commented 1 year ago

thanks for checking this out

I will prepare a PR with a fix