Not had to solve this problem myself but I'd have a look at 'with_together' 
and set_fact so that you could create a new fact which contains all the 
information.
See 
http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-parallel-sets-of-data
 
for documentation about with_together.

Hope this helps,

Jon

On Friday, September 8, 2017 at 9:55:40 PM UTC+1, Chris7444 wrote:
>
> Hi
>
> I am very new with ansible and I am struggling to solve the following 
> "problem"
> I have two json inputs
>
> a list of "locations" (you can think them as stores).  For each 
> "location"I have the name and the unique ID
>
> and a list of "parts" .  For each item, I have an array which tells me in 
> which "locations" I can find the item
>
> I want to build an array of locations, for each location I want to know 
> the list of "items" available in this location
>
> I don;t know how to do that with ansible
>
> Thank you
>
> Chris
>
>
> locations with their IDs
> {
>   "offset": 0,
>   "locations": [
>     {
>       "name": "Dallas",
>       "id": "42086a89-910f-4903-6db5-1f40995a6920",
>       "foo": "value1"
>     },
>     {
>       "name": "Houston",
>       "id": "42083339-7472-0ed6-3c34-eb51865dd50f",
>       "foo": "something"
>     },
>     {
>       "name": "Austin",
>       "id": "42081ecb-ff7d-20c2-156f-1b748411eadd",
>       "foo": "sonethingelse"
>     }
>   ],
>   "count": 3,
>   "bar": 500
> }
>
>
> parts 
>
> {
>   "foo": 500,
>   "count": 3,
>   "items": [
>     {
>       "name": "item1",
>       "locations": [
>         {
>           "id": "42083339-7472-0ed6-3c34-eb51865dd50f"
>         },
>         {
>           "id": "42086a89-910f-4903-6db5-1f40995a6920"
>         }
>       ],
>       "foobar": "Yes"
>     },
>     {
>       "name": "item2",
>       "locations": [
>         {
>           "id": "42083339-7472-0ed6-3c34-eb51865dd50f"
>         },
>         {
>           "id": "42081ecb-ff7d-20c2-156f-1b748411eadd"
>         }
>       ],
>       "foobar": "No"
>     },
>     {
>       "name": "item3",
>       "locations": [
>         {
>           "id": "42083339-7472-0ed6-3c34-eb51865dd50f"
>         },
>         {
>           "id": "42081ecb-ff7d-20c2-156f-1b748411eadd"
>         }
>       ],
>       "foobar": "Sure"
>     }
>   ]
> }
>
> and I want to build this (or a variable that will let me find which parts 
> are available in each location)
>
> {
> "locations": [
> {
> "name": "Dallas",
> "parts": [
> {"item": "item1"}
> ]
> },
> {
> "name": "Houston",
> "parts": [
> {"item": "item2"},
> {"item": "item3"},
> {"item": "item1"}
> ]
> },
> {
> "name": "Austin",
> "parts": [
> {"item": "item2"},
> {"item": "item3"}
> ]
> }
> ]
> }
>
>
>

-- 
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/0066ed22-9b82-4538-9760-7b161b80d061%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to