# trouble iterating through stdout\_lines

**URL:** <https://forum.ansible.com/t/trouble-iterating-through-stdout-lines/26908>\
**Category:** Ansible Project\
**Created:** [March 6, 2018, 10:49am UTC](https://forum.ansible.com/t/trouble-iterating-through-stdout-lines/26908 "2018-03-06T10:49:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcG](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@MarcG](https://forum.ansible.com/u/MarcG)\
**Post date:** [March 6, 2018, 10:49am UTC](https://forum.ansible.com/t/trouble-iterating-through-stdout-lines/26908/1 "2018-03-06T10:49:30Z")

</div>

```auto
Hi, I am trying to work out how to iterate through some results from a command I am running on a network device. the idea is when I find the line that matches what I am looking for based on a regexp I want to store it.

```

```auto

```

```auto

```

`

tasks:

- name: get the existing access-list  
ios\_command:  
provider: “{{ cli }}”  
commands:

- show access-list mgtaccess  
register: result

- debug: var=result.stdout\_lines

- name: Do something with each result  
debug:  
msg: “{{ item }}”  
with\_items:

- “{{ result.stdout\_lines }}”

`

```auto

```

```auto
This is the output from the task

```

```auto

```

`

ok: [172.16.1.135] =\> (item=[u’Standard IP access list mgtaccess’, u’ 20 permit 10.1.1.1’, u’ 10 permit 192.168.0.1’, u’ 30 permit any (2566 matches)']) =\> {  
“changed”: false,  
“failed”: false,  
“item”: [  
“Standard IP access list mgtaccess”,  
" 20 permit 10.1.1.1",  
" 10 permit 192.168.0.1",  
" 30 permit any (2566 matches)"  
],

“msg”: [  
“Standard IP access list mgtaccess”,  
" 20 permit 10.1.1.1",  
" 10 permit 192.168.0.1",  
" 30 permit any (2566 matches)"

]  
}  
`

```auto

I'm confused shouldn't I be seeing multiple individual 'msg's??

Many thanks.

```

---

<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:** [March 6, 2018, 6:35pm UTC](https://forum.ansible.com/t/trouble-iterating-through-stdout-lines/26908/2 "2018-03-06T18:35:57Z")

</div>

result.stdout\_lines is a list that contains lists  
So you have result.stdout\_lines.0.0 the first line, result.stdout\_lines.0.1 the second one and so on.

You can do  
&nbsp;&nbsp;with\_items: '{{ result.stdout\_lines.0 }}'  
to get what you are after.
