Its not clear to me exactly what you want the result to be after your 
set_fact processing but I suggest you take a look at json_query plugin as 
you might be able to use this to just pick out the bits of the result that 
you need.  
See 
http://docs.ansible.com/ansible/latest/playbooks_filters.html#json-query-filter 
 

One of the nice things about json_query is you can use the JMESPath 
examples page here: http://jmespath.org/examples.html to try out your 
queries (just paste your json into an input box and tinker with the query 
until you get results you need.

Hope this helps,

Jon

On Monday, February 12, 2018 at 7:58:47 AM UTC, Pieter Steyn wrote:
>
> Hi guys
>
> 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 }}
>
>
> Output:
>
> {
>     "profiles_dicts": [
>         {
>             "ENV": "env",
>             "Server": "epn-was8-dmgr-trn"
>         },
>         {
>             "ENV": "env",
>             "Server": "epn-was8-node-trn-01"
>         },
>         {
>             "ENV": "env",
>             "Server": "epn-was8-node-ppe-01"
>         },
>         {
>             "ENV": "env",
>             "Server": "epn-was8-dmgr-ppe"
>         }
>
>
> Is it possible to change my loop in order for my output to be ENV to match 
> PPE or TRN and not env?
>
> I am not sure how to achieve this
>
>
>

-- 
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/9719a9d2-a156-4a6a-89c5-ce29433a46db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to