Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra + in the {% endfor +%} block causing playbook to fail. #488

Closed
guillaumeldc opened this issue Oct 17, 2023 · 9 comments
Closed

Extra + in the {% endfor +%} block causing playbook to fail. #488

guillaumeldc opened this issue Oct 17, 2023 · 9 comments

Comments

@bboy8012
Copy link

Oh good, it's not just me. I was just starting to debug it to see where the error was.

@vitabaks
Copy link
Owner

@guillaumeldc Thanks!

here is a recent commit that added '+' to 'endfor':

de4d400#diff-6cd5a640c38bf41a44e6115d2ab9d552e4cc4f41fbd78ac2a3ff9d2faee706a4

@vitabaks
Copy link
Owner

vitabaks commented Oct 18, 2023

Until I can reproduce the problem with dcs_exists: true, what errors are you getting?

@vitabaks
Copy link
Owner

vitabaks commented Oct 18, 2023

On the contrary, without using '+' ({% endfor %}) I got incorrect formatting and hence the Patroni error

etcd3:
  hosts: 10.172.0.20:2379,10.172.0.21:2379,10.172.0.22:2379  username: etcd
  password: etcd-pass

journalctl -u patroni -n 100

Oct 18 11:04:49 pgnode01 systemd[1]: Started Runners to orchestrate a high-availability PostgreSQL - Patroni.
Oct 18 11:04:49 pgnode01 patroni[17608]: Traceback (most recent call last):
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/bin/patroni", line 8, in <module>
Oct 18 11:04:49 pgnode01 patroni[17608]:     sys.exit(main())
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 191, in main
Oct 18 11:04:49 pgnode01 patroni[17608]:     return patroni_main(args.configfile)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 162, in patroni_main
Oct 18 11:04:49 pgnode01 patroni[17608]:     abstract_main(Patroni, configfile)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/daemon.py", line 168, in abstract_main
Oct 18 11:04:49 pgnode01 patroni[17608]:     config = Config(configfile)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/config.py", line 214, in __init__
Oct 18 11:04:49 pgnode01 patroni[17608]:     self._local_configuration = self._load_config_file()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/config.py", line 263, in _load_config_file
Oct 18 11:04:49 pgnode01 patroni[17608]:     config = self._load_config_path(self._config_file)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/local/lib/python3.10/dist-packages/patroni/config.py", line 255, in _load_config_path
Oct 18 11:04:49 pgnode01 patroni[17608]:     config = yaml.safe_load(f)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 162, in safe_load
Oct 18 11:04:49 pgnode01 patroni[17608]:     return load(stream, SafeLoader)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 114, in load
Oct 18 11:04:49 pgnode01 patroni[17608]:     return loader.get_single_data()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/constructor.py", line 49, in get_single_data
Oct 18 11:04:49 pgnode01 patroni[17608]:     node = self.get_single_node()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 36, in get_single_node
Oct 18 11:04:49 pgnode01 patroni[17608]:     document = self.compose_document()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 55, in compose_document
Oct 18 11:04:49 pgnode01 patroni[17608]:     node = self.compose_node(None, None)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 84, in compose_node
Oct 18 11:04:49 pgnode01 patroni[17608]:     node = self.compose_mapping_node(anchor)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 133, in compose_mapping_node
Oct 18 11:04:49 pgnode01 patroni[17608]:     item_value = self.compose_node(node, item_key)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 84, in compose_node
Oct 18 11:04:49 pgnode01 patroni[17608]:     node = self.compose_mapping_node(anchor)
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
Oct 18 11:04:49 pgnode01 patroni[17608]:     while not self.check_event(MappingEndEvent):
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/parser.py", line 98, in check_event
Oct 18 11:04:49 pgnode01 patroni[17608]:     self.current_event = self.state()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/parser.py", line 428, in parse_block_mapping_key
Oct 18 11:04:49 pgnode01 patroni[17608]:     if self.check_token(KeyToken):
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/scanner.py", line 116, in check_token
Oct 18 11:04:49 pgnode01 patroni[17608]:     self.fetch_more_tokens()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/scanner.py", line 223, in fetch_more_tokens
Oct 18 11:04:49 pgnode01 patroni[17608]:     return self.fetch_value()
Oct 18 11:04:49 pgnode01 patroni[17608]:   File "/usr/lib/python3/dist-packages/yaml/scanner.py", line 577, in fetch_value
Oct 18 11:04:49 pgnode01 patroni[17608]:     raise ScannerError(None, None,
Oct 18 11:04:49 pgnode01 patroni[17608]: yaml.scanner.ScannerError: mapping values are not allowed here
Oct 18 11:04:49 pgnode01 patroni[17608]:   in "/etc/patroni/patroni.yml", line 18, column 70
Oct 18 11:04:49 pgnode01 systemd[1]: patroni.service: Main process exited, code=exited, status=1/FAILURE

@vitabaks
Copy link
Owner

And current code ({% endfor +%})

etcd3:
  hosts: 10.172.0.20:2379,10.172.0.21:2379,10.172.0.22:2379
  username: etcd
  password: etcd-pass
root@pgnode01:/# journalctl -u patroni -n 10
Oct 18 11:22:10 pgnode01 patroni[26397]: 2023-10-18 11:22:10,443 INFO: no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:20 pgnode01 patroni[26397]: INFO:patroni.ha:Lock owner: pgnode01; I am pgnode01
Oct 18 11:22:20 pgnode01 patroni[26397]: INFO:patroni.__main__:no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:20 pgnode01 patroni[26397]: 2023-10-18 11:22:20,443 INFO: no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:30 pgnode01 patroni[26397]: INFO:patroni.ha:Lock owner: pgnode01; I am pgnode01
Oct 18 11:22:30 pgnode01 patroni[26397]: INFO:patroni.__main__:no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:30 pgnode01 patroni[26397]: 2023-10-18 11:22:30,447 INFO: no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:40 pgnode01 patroni[26397]: INFO:patroni.ha:Lock owner: pgnode01; I am pgnode01
Oct 18 11:22:40 pgnode01 patroni[26397]: INFO:patroni.__main__:no action. I am (pgnode01), the leader with the lock
Oct 18 11:22:40 pgnode01 patroni[26397]: 2023-10-18 11:22:40,447 INFO: no action. I am (pgnode01), the leader with the lock
postgres@pgnode01:~$ patronictl list
+ Cluster: postgres-cluster -------+-----------+----+-----------+
| Member   | Host        | Role    | State     | TL | Lag in MB |
+----------+-------------+---------+-----------+----+-----------+
| pgnode01 | 10.172.0.20 | Leader  | running   |  2 |           |
| pgnode02 | 10.172.0.21 | Replica | streaming |  2 |         0 |
| pgnode03 | 10.172.0.22 | Replica | streaming |  2 |         0 |
+----------+-------------+---------+-----------+----+-----------+

@vitabaks
Copy link
Owner

So I'm not sure if this part of the code needs fixing.

Please give more information about your error.

@guillaumeldc
Copy link
Author

Hi @vitabaks sorry for the short (no) description in filing the error.
Not sure if we are talking about the same thing. In the jinja template, in the patroni role there is definitely a typo line 38 resulting in the following error when executing the playbook:

AnsibleError: template error while templating string: expected token 'end of statement block', got '+'

Unless my knowledges in Jinja templating are already outdated, the "+" doesn't belong there.

This is the code I'm talking about:

{% if not dcs_exists|bool and dcs_type == 'etcd' %}
etcd3:
  hosts: {% for host in groups['etcd_cluster'] %}{{ hostvars[host]['inventory_hostname'] }}:2379{% if not loop.last %},{% endif %}{% endfor %}
{% endif %}
{% if dcs_exists|bool and dcs_type == 'etcd' %}
etcd3:
  hosts: {% for etcd_hosts in patroni_etcd_hosts %}{{etcd_hosts.host}}:{{etcd_hosts.port}}{% if not loop.last %},{% endif %}
### this is not correct below
 {% endfor +%}

@guillaumeldc
Copy link
Author

Removing the "+" corrected my issue and the playbook ran smoothly.

@vitabaks
Copy link
Owner

@guillaumeldc Ok, I removed the '+' and added an empty string before the condition for the variable 'patroni_etcd_username' to avoid formatting issues.

Could you test this?

PR: #490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@bboy8012 @vitabaks @guillaumeldc and others