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

ansible error #615

Open ayadahm opened 1 month ago

ayadahm commented 1 month ago

Hi Vitabaks I got the following error When trying to run ansible-playbook deploy_pgcluster.yml. My choice was pgbouncer_install: false and I did not ON any postgresql_parameters on main.yml (assuming that postgresql will be installed with default parameters from postgresql.conf)

Should I choose the minimun max_connections from the list in mail.yml ?? why ?

TASK [pre-checks : Set max_connections from vars or use default] **************************************************************************
task path: /--/--/--/--/--/postgresql_cluster/roles/pre-checks/tasks/pgbouncer.yml:5
fatal: [195.231.167.54]: FAILED! => {"msg": "Invalid data passed to 'loop', it requires a list, got this instead: . Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."}
vitabaks commented 1 month ago

Hi @ayadahm ! I'll check it out.

ayadahm commented 1 month ago

Many thanks.

There is also an error if I choose pg_stat_statements for installation from the list of extensions.

TASK [Include main variables] *************************************************************************************************************
fatal: [195.231.167.54]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: Expecting value: line 1 column 1 (char 0)\n\nSyntax Error while loading YAML.\n  did not find expected key\n\nThe error appears to be in '/home/am/ANSIBLE/new_unilogin/patroni_from_github/postgresql_cluster/vars/main.yml': line 175, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\npostgresql_extensions: []\n  - { ext: \"pg_stat_statements\", db: \"postgres\" }\n  ^ here\nThis one looks easy to fix. It seems that there is a value started\nwith a quote, and the YAML parser is expecting to see the line ended\nwith the same kind of quote. For instance:\n\n    when: \"ok\" in result.stdout\n\nCould be written as:\n\n   when: '\"ok\" in result.stdout'\n\nOr equivalently:\n\n   when: \"'ok' in result.stdout\"\nWe could be wrong, but this one looks like it might be an issue with\nunbalanced quotes. If starting a value with a quote, make sure the\nline ends with the same set of quotes. For instance this arbitrary\nexample:\n\n    foo: \"bad\" \"wolf\"\n\nCould be written as:\n\n    foo: '\"bad\" \"wolf\"'\n"}
fatal: [195.231.167.41]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: Expecting value: line 1 column 1 (char 0)\n\nSyntax Error while loading YAML.\n  did not find expected key\n\nThe error appears to be in '/home/am/ANSIBLE/new_unilogin/patroni_from_github/postgresql_cluster/vars/main.yml': line 175, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\npostgresql_extensions: []\n  - { ext: \"pg_stat_statements\", db: \"postgres\" }\n  ^ here\nThis one looks easy to fix. It seems that there is a value started\nwith a quote, and the YAML parser is expecting to see the line ended\nwith the same kind of quote. For instance:\n\n    when: \"ok\" in result.stdout\n\nCould be written as:\n\n   when: '\"ok\" in result.stdout'\n\nOr equivalently:\n\n   when: \"'ok' in result.stdout\"\nWe could be wrong, but this one looks like it might be an issue with\nunbalanced quotes. If starting a value with a quote, make sure the\nline ends with the same set of quotes. For instance this arbitrary\nexample:\n\n    foo: \"bad\" \"wolf\"\n\nCould be written as:\n\n    foo: '\"bad\" \"wolf\"'\n"}
fatal: [195.231.167.52]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: Expecting value: line 1 column 1 (char 0)\n\nSyntax Error while loading YAML.\n  did not find expected key\n\nThe error appears to be in '/home/am/ANSIBLE/new_unilogin/patroni_from_github/postgresql_cluster/vars/main.yml': line 175, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\npostgresql_extensions: []\n  - { ext: \"pg_stat_statements\", db: \"postgres\" }\n  ^ here\nThis one looks easy to fix. It seems that there is a value started\nwith a quote, and the YAML parser is expecting to see the line ended\nwith the same kind of quote. For instance:\n\n    when: \"ok\" in result.stdout\n\nCould be written as:\n\n   when: '\"ok\" in result.stdout'\n\nOr equivalently:\n\n   when: \"'ok' in result.stdout\"\nWe could be wrong, but this one looks like it might be an issue with\nunbalanced quotes. If starting a value with a quote, make sure the\nline ends with the same set of quotes. For instance this arbitrary\nexample:\n\n    foo: \"bad\" \"wolf\"\n\nCould be written as:\n\n    foo: '\"bad\" \"wolf\"'\n"}
vitabaks commented 1 month ago

@ayadahm I have not been able to reproduce the issue with the pgbouncer pre-check.

please attach an archive of your variable files so that I can study them.

ayadahm commented 1 month ago

Debian.yml.txt system.yml.txt Here they are: main.txt

vitabaks commented 2 weeks ago

@ayadahm I'm sorry for the long answer.

Is this problem still relevant?

ayadahm commented 2 weeks ago

Hi yes

SDV109 commented 5 days ago

@ayadahm Hi! You made mistakes in vars/main.yml in each of the cases you described: 1) When you commented out all the points of postgresql_parameters, you violated the syntax of yaml files, because after: you need to specify either a specific value or list it, and you get to comment out the list, but did not indicate that in your case postgresql_patameters is empty, for this you need to make the following postgresql_parameters construction : [] - this construction indicates that nothing is used from postgresql_parameters in this example. But in this case, there is an error in the algorithm, I will inform @vitabaks for correction, but I think that most likely according to the further algorithm, there would also be other errors due to the syntax. To summarize, you need to change main.yml like this:

postgresql_parameters: []
#  - { option: "max_connections", value: "500" }

2) In the second case, there is a YML syntax error again, and you are specifically told: /home/am/ANSIBLE/new_unilogin/patroni_from_github/postgresql_cluster/vars/main.yml': line 175, column 3 Ansible errors, of course, do not always describe exactly how to make a correction, but most often indicate the place where the correction needs to be made.

postgresql_extensions: []
  - { ext: "pg_stat_statements", db: "postgres" }

In your case, the error was that you passed as postgresql_extensions with an empty list, and after the postgresql_extensions variable, you have - {ext: "pg_stat_statements", db: "postgres"}, which ansible cannot recognize, since it is part of the list, and the variable is not open for lists. To summarize, you need to change main.yml like this:

postgresql_extensions: 
  - { ext: "pg_stat_statements", db: "postgres" }
vitabaks commented 5 days ago

Thanks @SDV109

ayadahm commented 4 days ago

Many thanks for the correction. I will try that out. Cheers.