On Wed, 5 Feb 2020 06:25:18 -0800 (PST) Anand Solomon <[email protected]> wrote:
> value1: Something1
> value2: Something2
>
> privs1: privs_value1
> privs2: privs_value2
>
> In my playbook, I want to iterate this
>
> value: "{{value1}}"
> privilege: "{{privs1}}"
>
> value: "{{value2}}"
> privilege: "{{privs2}}"
Create the lists of the variables and use "zip" too loop them. For example
- set_fact:
value_keys: "{{ hostvars[inventory_hostname].keys()|
select('match', '^value(.*)$')|
list|sort }}"
- set_fact:
value_list: "{{ value_keys|
map('extract', hostvars[inventory_hostname])|
list }}"
- set_fact:
privs_keys: "{{ hostvars[inventory_hostname].keys()|
select('match', '^privs(.*)$')|
list|sort }}"
- set_fact:
privs_list: "{{ privs_keys|
map('extract', hostvars[inventory_hostname])|
list }}"
- debug:
msg: "value: {{ item.0 }} privilege: {{ item.1 }}"
loop: "{{ value_list|zip(privs_list)|list }}"
give
"msg": "value: Something1 privilege: privs_value1"
"msg": "value: Something2 privilege: privs_value2"
HTH,
-vlado
--
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/20200205171156.457e6e31%40gmail.com.
pgpgm2kFZSfyA.pgp
Description: OpenPGP digital signature
