简体   繁体   English

Ansible:无法访问 group_vars 文件中的嵌套变量

[英]Ansible: Unable to access nested variable in group_vars file

I have the following playbook where I am testing the access to values in my group_vars file.我有以下剧本,我正在测试对 group_vars 文件中的值的访问。 The first Task run fine, but the second one is failing.第一个任务运行良好,但第二个任务失败。 I thought that was the correct syntax to access nested data from a vars file.我认为这是从 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'

I have the following data structure in my group_vars file:我的 group_vars 文件中有以下数据结构:

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

Playbook:剧本:

---
- 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 }}"

Doh!哦! I was not able to use numbers in my group_vars file to signify objects in the array.我无法在 group_vars 文件中使用数字来表示数组中的对象。 We use a numberical system to identify our various test environments, so I wanted to use those in my group_vars file.我们使用数字系统来识别我们的各种测试环境,所以我想在我的 group_vars 文件中使用它们。

Had to do it like this:不得不这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM