【问题标题】:Ansible variable "not found" in second reference第二个参考中的 Ansible 变量“未找到”
【发布时间】:2021-03-29 18:42:26
【问题描述】:

我在我引用的文件中有一个变量,就像在“vars_files”文件中一样。它看起来可以工作一次,然后在后续引用中失败。

---
- hosts:  asa
  gather_facts: no
  connection: local 
  vars_files:
    - /var/lib/awx/projects/vpn/clientData

  tasks:

   - name: Build object group
     asa_config:
       lines:
         - "object network {{ client_name }}"
         - "subnet {{ app_net }} {{ app_net_mask }}" 

   - name: Build tunnel interface
     asa_config:
       lines:
         - "interface Tunnel {{ client_id }}"
         - "nameif VTI-{{ client_name }}"
         - "ip address {{ netaddr }} 255.255.255.252"
         - "tunnel source interface outside"
         - "tunnel destination {{ client_pub_ip }}"
         - "tunnel mode ipsec ipv4"
         - "tunnel protection ipsec profile PROFILE1" 

   - name: Build tunnel groups
     asa_config:
       lines:
         - "tunnel-group {{ client_pub_ip }} type ipsec-l2l" 
         - "tunnel-group {{ client_pub_ip }} ipsec-attributes"
         - "ikev2 remote-authentication pre-shared-key {{ psk_data }}"
         - "ikev2 local-authentication pre-shared-key {{ psk_data }}"

   - name: Build BGP
     asa_config:
       lines:
         - "neighbor {{ netaddr }} remote-as {{ bgp_as }}"
         - "neighbor {{ netadrr }} activate"
       parents:
         - router bgp 100
         - address-family ipv4 unicast

   - name: Save
     asa_config:
       save: yes 

该变量在“构建隧道接口”中找到,但 Ansible 在“构建 BGP”部分抛出“未找到变量”。

task path: /var/lib/awx/projects/vpn/add-ecc-client-v1.yaml:35
fatal: [192.168.254.92]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'netadrr' is undefined\n\nThe error appears to be in '/var/lib/awx/projects/vpn/add-ecc-client-v1.yaml': line 45, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - name: Build BGP\n     ^ here\n"
}

vars_files 内容:

client_name: kkk
client_pub_ip: 20.1.1.11
app_net: 11.11.11.0
app_net_mask: 255.255.255.0
client_id: 1111
bgp_as: 1111


psk_data: Yh8F9FJ14mS86gOWc2MdOwjXsiqNiEJVGjicPlmzRAv0UQypJhWNNckn3YggfupxUHy0qH3QHpZ
netaddr: 169.254.100.50

我错过了什么?

谢谢

【问题讨论】:

  • 您似乎遗漏了您收到的实际错误,以及您已经为自己解决问题所做的故障排除尝试。互联网上的任何人都无法猜测发生在你身上的事情
  • 我会建议它因为bgp_as而抛出它。
  • 请显示包含的 var 文件和 var 定义。

标签: ansible yaml


【解决方案1】:

祝你好运。 . . "netadrr" 在第二个引用中。

打扰了

【讨论】:

  • 我很高兴这很简单 :-) 请注意,您可以删除自己的问题,以省去关闭它的麻烦,因为“由错字引起,不太可能帮助未来的读者”跨度>
猜你喜欢
  • 2020-09-22
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多