I want to use variable in iosxr_config lines in ansible playbook. I have tried the following code.
- hosts: 116.119.4.1
connection: local
vars:
trapdests: []
tasks:
- name: show version
register: command_out
iosxr_command:
commands: "sh ipv4 interface brief | include Loopback0"
- debug:
var: command_out.stdout
- name: trapping the Loopback ip
register: trapdests
set_fact:
trapdests: "{{[item.split()[1]]}}"
with_items: "{{command_out.stdout_lines}}"
- debug:
var: trapdests
# tasks:
- name: enable PCEP
iosxr_config:
lines:
- traffic-eng
- pcc
- source-address ipv4 "{{item}}"
- pce address ipv4 100.67.249.67
- precedence 100
with_items: "{{trapdests}}"
parents: segment-routing
Basically I want to use the variable at the end of this command---> source-address ipv4 "{{item}}". But I'm getting the following error:
TASK [enable PCEP] **********************************************************************************************************************************************************************************************
fatal: [116.119.4.1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to have been in '/home/cisco/pcep_enble_test_2.yml': line 20, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# tasks:\n - name: enable PCEP\n ^ here\n"}
to retry, use: --limit @/home/cisco/pcep_enble_test_2.retry
PLAY RECAP ******************************************************************************************************************************************************************************************************
116.119.4.1 : ok=5 changed=0 unreachable=0 failed=1
Can anybody help me out please. Thanks in advance.
It seems you have a syntax error. With_item have to be on task level:
- name: enable PCEP
iosxr_config:
lines:
- traffic-eng
- pcc
- source-address ipv4 "{{ item }}"
- pce address ipv4 100.67.249.67
- precedence 100
parents: segment-routing
with_items: "{{ trapdests }}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.