[英]How to use a variable in iosxr_config lines in ansible playbook
我想在 ansible playbook 的 iosxr_config 行中使用变量。 我试过下面的代码。
- 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
基本上我想在这个命令的末尾使用变量---> source-address ipv4 "{{item}}"。 但我收到以下错误:
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
任何人都可以帮助我。 提前致谢。
您似乎有语法错误。 With_item 必须在任务级别:
- 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 }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.