On 12.02.2018 08:58, Pieter Steyn wrote:
I need some help with looping my local_facts as I am struggling to
match
the key/value
Example of my facts file:
{
"env": [
"ppe",
"trn"
],
"websphere_dir": "/WebSphere8",
"tech": "was8",
"profiles": {
"epn-was8-dmgr-ppe": {
"env": "ppe"
},
"epn-was8-dmgr-trn": {
"env": "trn"
},
"epn-was8-node-ppe-01": {
"env": "ppe"
},
"epn-was8-node-trn-01": {
"env": "trn"
}
}
}
Code in playbook:
- set_fact:
profiles_dicts: |
{% set res = [] -%}
{% for key in ansible_local.was.profiles.keys() -%}
{% for value in ansible_local.was.profiles[key] -%}
{% set ignored = res.extend([{'Server': key,
'ENV':value}])
-%}
{%- endfor %}
{%- endfor %}
{{ res }}
You could do something like this
- set_fact:
profiles_dicts: |
{% set res = [] -%}
{% for key, value in ansible_local.was.profiles.iteritems() -%}
{% set ignored = res.extend([{'Server': key,
'ENV':value.env}]) -%}
{%- endfor %}
{{ res }}
--
Kai Stian Olstad
--
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/cfe9f143c8047b062e111ca742b1866b%40olstad.com.
For more options, visit https://groups.google.com/d/optout.