Hello,
Your testing looks fine in the test data model. However, the sssd_config
real data model is like below:
sssd_config:
sssd:
debug_level: 1
additional_key: additional_value
another_addtional_key: another_additional_value
nss:
reconnection_retries: 3
additional_key: additional_value
another_addtional_key: another_additional_value
pam:
debug_level: 5
additional_key: additional_value
another_addtional_key: another_additional_value
The addtional_key and another_additional_key isn't same per section
(pam,nss,sssd), and number of additional_key per section isn't identical
either. So nss section may have 5 key/value pairs, pam may have 6 key/value
pairs, and sssd may have only 3 key/value pairs. Each additional_key is
pretty much unique to that section.
Because this is so difficult to manipulate in template (I spend most
yesterday to figure it out), I think it is probably better just put
INI-style content into template file, then fill in the values from
variables that varies for that key/value pair. It makes the work more
simpler.
Thank you for providing the test case. I'll remember this lesson.
- Xinhuan
On Wednesday, January 15, 2020 at 3:45:44 PM UTC-5, Vladimir Botka wrote:
>
> On Wed, 15 Jan 2020 11:57:49 -0800 (PST)
> Xinhuan Zheng <[email protected] <javascript:>> wrote:
>
> > I tested the solution, it doesn't work. item.1 becomes:
> > {u'id_provider': u'local', u'auth_provider': u'local', u'enumerate':
> True}
> > So I get error there is no keys on {{ item.1.keys().0 }}
>
> Both versions works for me. Double-check the code. The playbook
>
> - hosts: localhost
> vars:
> sssd_config:
> sssd:
> debug_level: 1
> nss:
> reconnection_retries: 3
> pam:
> debug_level: 5
> tasks:
> - template:
> src: template.j2
> dest: config.ini
>
> with the template
>
> % for item in sssd_config.items() %}
> [{{ item.0 }}]
> {{ item.1.keys().0 }}={{ item.1.values().0 }}
> {% endfor %}
> # ------------------------------------------
> {% for item in sssd_config.items() %}
> [{{ item.0 }}]
> {% for iitem in item.1.items() %}
> {{ iitem.0 }}={{ iitem.1 }}
> {% endfor %}
> {% endfor %}
>
> gives
>
> [nss]
> reconnection_retries=3
> [pam]
> debug_level=5
> [sssd]
> debug_level=1
> # ------------------------------------------
> [nss]
> reconnection_retries=3
> [pam]
> debug_level=5
> [sssd]
> debug_level=1
>
> --
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2b863977-2dc5-425f-86f9-e4d7130fad70%40googlegroups.com.