# with\_item and access array to pass separate value each time loop is executed

**URL:** <https://forum.ansible.com/t/with-item-and-access-array-to-pass-separate-value-each-time-loop-is-executed/23286>\
**Category:** Ansible Project\
**Created:** [December 19, 2016, 7:01pm UTC](https://forum.ansible.com/t/with-item-and-access-array-to-pass-separate-value-each-time-loop-is-executed/23286 "2016-12-19T19:01:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcin\_zimnica](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@marcin\_zimnica](https://forum.ansible.com/u/marcin_zimnica)\
**Post date:** [December 19, 2016, 7:01pm UTC](https://forum.ansible.com/t/with-item-and-access-array-to-pass-separate-value-each-time-loop-is-executed/23286/1 "2016-12-19T19:01:23Z")

</div>

Hi,

I have following code and trying to figure out how I can pass each value from array access to the eos\_config using iteration. I want to run the scripts eos\_config only on all access port not routed.

- name: change description  
hosts: arista  
connection: local

vars:  
access:

tasks:

- name: show interface  
eos\_command:  
commands:

- sh interfaces ethernet {{ item.if }} switchport | json  
provider: “{{ cli }}”  
with\_items:

- { if: ‘1’}

- { if: ‘2’}

- { if: ‘3’}  
register: showif

- name: set access fact  
set\_fact:  
access: “{{ access + [item] }}”  
with\_items:

- “{{showif.results[0].stdout[0].switchports.Ethernet1.enabled}}”

- “{{showif.results[1].stdout[0].switchports.Ethernet2.enabled}}”

- “{{showif.results[2].stdout[0].switchports.Ethernet3.enabled}}”  
when: ‘“mode” is defined’

- debug: var=access

- name: change description  
eos\_config:  
lines:

- description ansible\_test  
parents: interface ethernet {{item.if}}  
provider: “{{ cli }}”  
authorize: yes  
with\_items:

- { if: ‘1’ }

- { if: ‘2’ }

- { if: ‘3’ }  
when: ‘access == true’

I am able to extract info about each port and assigne true value if port is access or false when is routed

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/arista.yaml:28  
ok: [10.10.10.101] =\> {  
“access”: [  
true,  
true,  
false  
]  
}

Now I would like to access this variable when running this part of code but dont know really how to do it.

- name: change description  
eos\_config:  
lines:
- description ansible\_test  
parents: interface ethernet {{item.if}}  
provider: “{{ cli }}”  
authorize: yes  
with\_items:
- { if: ‘1’ }
- { if: ‘2’ }
- { if: ‘3’ }  
when: ‘access == true’

I am getting following output for last part of the script

TASK [change description] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /etc/ansible/arista.yaml:30  
skipping: [10.10.10.101] =\> (item={u’if’: u’2’}) =\> {  
“changed”: false,  
“item”: {  
“if”: “2”  
},  
“skip\_reason”: “Conditional check failed”,  
“skipped”: true  
}  
skipping: [10.10.10.101] =\> (item={u’if’: u’1’}) =\> {  
“changed”: false,  
“item”: {  
“if”: “1”  
},  
“skip\_reason”: “Conditional check failed”,  
“skipped”: true  
}  
skipping: [10.10.10.101] =\> (item={u’if’: u’3’}) =\> {  
“changed”: false,  
“item”: {  
“if”: “3”  
},  
“skip\_reason”: “Conditional check failed”,  
“skipped”: true  
}

Does any one know how to achieve this goal or what I am missing?

Regards,

Marcin
