Re: [ansible-project] populating dictionary from lookup
Thank you, Vladimir. I've completely forgotten that ansible allows vars to be defined for a single task. On Fri, Sep 30, 2022 at 12:18 AM Vladimir Botka wrote: > The next option is putting the iteration into one task. For example, > > - set_fact: > soarecords_dict: "{{ soarecords_dict|d({})| > combine({item: _dict}) }}" > loop: "{{ zones }}" > vars: > _dict: "{{ dict(soafields| >zip(lookup('dig', item, 'qtype=SOA')|split)) }}" > > > -- > Vladimir Botka > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMB-ck6N10vx5%2BNhyV7X_y1nbwwrdXEyZfNfXhuXe1aLHw9Ljg%40mail.gmail.com.
Re: [ansible-project] populating dictionary from lookup
The next option is putting the iteration into one task. For example, - set_fact: soarecords_dict: "{{ soarecords_dict|d({})| combine({item: _dict}) }}" loop: "{{ zones }}" vars: _dict: "{{ dict(soafields| zip(lookup('dig', item, 'qtype=SOA')|split)) }}" -- Vladimir Botka -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20220929231757.660a4999%40gmail.com. pgp79kaSj20Ki.pgp Description: OpenPGP digital signature
Re: [ansible-project] populating dictionary from lookup
Create it in Jinja. For example, soarecords: | {% for zone in zones %} {{ zone }}: {% for field in lookup('dig', zone, 'qtype=SOA')|split %} {{ soafields[loop.index0] }}: {{ field }} {% endfor %} {% endfor %} soarecords_dict: "{{ soarecords|from_yaml }}" -- Vladimir Botka -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20220929230403.4de13028%40gmail.com. pgp884lEqybqg.pgp Description: OpenPGP digital signature
[ansible-project] populating dictionary from lookup
Hello As a part of another project, I have written a playbook: --- - hosts: localhost vars: tdict: zones: - example.com - example.org - example.net soafields: - nameserver - admin - serial - refresh - retry - expire - ttl soarecords_dict: tasks: - name: read soa record into dict set_fact: tdict: "{{ tdict | combine( {item : lookup('dig',item,'qtype=SOA')|split } )}}" loop: "{{ zones }}" - debug: msg: "{{ tdict.keys() | list }}" - set_fact: soarecords_dict: "{{ soarecords_dict | combine ({item : dict(soafields| zip(tdict[item]))}) }}" loop: "{{ tdict.keys() |list }}" - name: output soa records debug: var: soarecords_dict this works, but if possible, I want to get rid of temporary tdict part, meaning that I will set soarecords_dict variable directly from oneliner. doable? -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c55933e7-c2ea-4a71-a901-1e041764b41en%40googlegroups.com.