[英]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.