# Access specific elements using with\_items / with\_subelememts

**URL:** <https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543>\
**Category:** Ansible Project\
**Created:** [January 28, 2019, 3:21pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543 "2019-01-28T15:21:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saranya\_N](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Saranya\_N](https://forum.ansible.com/u/Saranya_N)\
**Post date:** [January 28, 2019, 3:21pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543/1 "2019-01-28T15:21:18Z")

</div>

I have a variable file with dictionary under a role like below format :

Applformat:  
&nbsp;&nbsp;&nbsp;- Appname : app-main  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parameters:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- x : a  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y : b  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Z : c

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- x : d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y : e  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- z : f  
&nbsp;&nbsp;&nbsp;- Appname : app-relay  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parameters:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- x : g  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y : h  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Z : I

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- x : j  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y : k  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Z : l

Etc many apps are there with different names.

I need to run a cli( my app command) that will make few apps as child n parent.

My command will be something like below.

Command : Kif run -parentappp {{ item.Appname }} -childapp {{ item.Appname }}  
With\_items :  
&nbsp;&nbsp;- "{{ Appname }}"

I need a logic in my play to state which app is parent and which is child and need assistance on this.

My first app is always the parent of second app.

So first command should take first app as parent and second app as child.

My second app is parent of the 3rd, 4th .. etc remaining apps.

So these two conditions should be satisfied during the loop.

Kindly assist

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 28, 2019, 3:45pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543/2 "2019-01-28T15:45:40Z")

</div>

Something like this should work

&nbsp;&nbsp;&nbsp;- command: Kif run -parentappp {{ Applformat[item | int].Appname }} -childapp {{ Applformat[item | int + 1].Appname }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_sequence: start=0 end={{ Applformat | length - 1 }} stride=2

---

<div class="post-metadata">

**Author:** ![Saranya\_N](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@Saranya\_N](https://forum.ansible.com/u/Saranya_N)\
**Post date:** [January 29, 2019, 2:11pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543/3 "2019-01-29T14:11:47Z")

</div>

Hi Kai ,

M getting below error and I wonder why ☹

Can't parse arg end=u'3\xa0stride=2' as integer .

Also please help me understand this,

My first app is parent of second and  
Second app is parent of Remaining apps i.e from 3rd app onwards .

So I think I'll need the above task twice with different sequence number to achieve the two conditions ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 2, 2019, 12:08pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543/4 "2019-02-02T12:08:01Z")

</div>

Just split it on two task with different with\_sequences

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 2, 2019, 12:09pm UTC](https://forum.ansible.com/t/access-specific-elements-using-with-items-with-subelememts/29543/5 "2019-02-02T12:09:36Z")

</div>

> Hi Kai ,
> 
> M getting below error and I wonder why ☹
> 
> Can't parse arg end=u'3\xa0stride=2' as integer .

You have gotten some strange character in there, delete it and write it again.

> Also please help me understand this,
> 
> My first app is parent of second and  
> Second app is parent of Remaining apps i.e from 3rd app onwards .
> 
> So I think I'll need the above task twice with different sequence  
> number to achieve the two conditions ?

Yes, that would be the easiest.
