I have the following ansible code:
“`
- name: Install and configure PGS servers for RZ
hosts: pgs_rzdb_servers
tasks:
- name: Prepare pgs_server role variables
set_fact:
pgs_server_custom_role_vars: >-
{{
{
'pgs_server_version': pgs_rzdb_server_version,
'pgs_server_port': pgs_rzdb_server_port,
'pgs_server_pg_hba_rules': pgs_rzdb_server_pg_hba_rules,
'pgs_server_max_connections': pgs_rzdb_server_max_connections,
'pgs_server_idle_in_transaction_session_timeout': pgs_rzdb_server_idle_in_transaction_session_timeout,
'pgs_server_marker': 'RZDB'
}
| dict2items
| selectattr('value', 'defined')
| items2dict
}}
- debug:
msg: "Role variables: {{ pgs_server_custom_role_vars }}"
- debug:
msg: "Role variables: {{ pgs_server_custom_role_vars | type_debug }}"
- name: pgs_server
import_role:
name: pgs_server
vars: "{{ pgs_server_custom_role_vars }}"
tags:
- pgs_server
Even though I get the following debug messages when I comment out vars:
TASK [debug] ************************************************************************************************************************************************************************************************************************************** ok: [lspostgres02.ls.local] => { "msg": "Role variables: {'ls_pgs_server_version': 13, 'ls_pgs_server_port': 5431, 'ls_pgs_server_pg_hba_rules': [{'contype': 'host', 'users': 'all', 'source': 'lxserver.ls.local', 'databases': 'all', 'method': 'md5'}, {'contype': 'host', 'users': 'all', 'source': '192.168.69.0/24', 'databases': 'all', 'method': 'md5'}], 'ls_pgs_server_marker': 'RZDB'}" }
TASK [debug] ************************************************************************************************************************************************************************************************************************************** ok: [lspostgres02.ls.local] => { "msg": "Role variables: dict" }
when I uncomment this line I get the following error:
ERROR! Vars in a IncludeRole must be specified as a dictionary
The error appears to be in '/mnt/c/Users/dhe/Documents/Checkouts/ls-ansible/ls_pgs_rzdb_servers.yml': line 30, column 13, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
name: pgs_server
vars: "{{ pgs_server_custom_role_vars }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Is this a bug, or what am I doing wrong here?
I’m using ansible [core 2.16.6]
I expect this to just work correctly, because the documentation of ansible tells me, that I have to pass
Dictionary/map of variables here.