【问题标题】:Ansible: Unable to access nested variable in group_vars fileAnsible:无法访问 group_vars 文件中的嵌套变量
【发布时间】:2020-02-22 23:16:33
【问题描述】:

我有以下剧本,我在其中测试对 group_vars 文件中值的访问。第一个任务运行良好,但第二个任务失败。我认为这是从 vars 文件访问嵌套数据的正确语法。

Failure message:
TASK [call 60 env FEX 141 uplink port from group_vars] ****************************************************************************************************************
fatal: [S70G1MS001]: FAILED! => {"msg": "The task includes an option with an undefined variable.  The error was: 'float object' has no attribute 'uplink'

我的 group_vars 文件中有以下数据结构:

60:
 141:
   uplink: Eth1/6
   description: "FEX101@AA33"
IZ2:
 SW1: S70G1MS001
 SW2: S70G2MS002

剧本:

---
- hosts: S70G1MS001
no_log: false
gather_facts: false
tasks:
  - name:  call IZ2 switch 2 from  group_vars
    debug:
      msg:
        - "{{ IZ2.SW2 }}"
  - name:  call 60 env FEX 141 uplink port from group_vars
    debug:
      msg:
        - "{{ 60.141.uplink }}"

【问题讨论】:

    标签: debugging ansible yaml


    【解决方案1】:

    哇!我无法在我的 group_vars 文件中使用数字来表示数组中的对象。我们使用数字系统来识别我们的各种测试环境,所以我想在我的 group_vars 文件中使用它们。

    必须这样做:

    TEST:
      191:
        uplink: Eth1/24
        description: "FEX101@AA33"
    

    【讨论】:

      猜你喜欢
      • 2015-08-10
      • 2021-12-01
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      相关资源
      最近更新 更多