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
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2691f823-4d4d-481b-a7fb-95a604d990e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.