- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是新来的 ansible
并按照说明 here它给出了两个用于引用键值字典的符号。
foo['field1']
foo.field1
并说“括号表示法始终有效”。我试试
vars:
- london:
- nodename : music0
- card: Headphone
- mixer: Hardware
- debug:
msg: nodename "{{ london[0] }} "
- debug:
msg: nodename "{{ london['nodename'] }} "
第一个冬季引用 [0] 似乎没问题:
TASK [debug] *******************************************************************
ok: [127.0.0.1] => {
"msg": "nodename \"{u'nodename': u'music0'} \""
}
但不是括号符号:
fatal: [127.0.0.1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'list object' has no attribute 'nodename'\n\nThe error appears to be in '/home/frank/Data/ansibleHost/testVars.yml': line 29, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}
与已发布的示例有何不同?我承认我不明白错误信息...
list object
应该是
london
其中有一个
attribute
- 还是我误解了变量声明?
最佳答案
对我来说,您的问题似乎是您正在混合 lists和 dictionaries .
london.nodename
访问其中的元素或 london['nodename']
london:
nodename: music0
card: Headphone
mixer: Hardware
foo:
- london:
- nodename: music0
- card: Headphone
- mixer: Hardware
您可以使用基于 0 的索引语法访问它:foo.0.london.0.nodename
但我非常怀疑这不是您正在寻找的数据结构。以与上述相同的方式,foo[0]['london'][0]['nodename']
也会工作fruits:
- banana
- apple
- orange
- lemon
然后对于基于 0 的索引的进一步解释,例如,您可以访问 orange
通过 fruits.2
或 fruits[2]
- hosts: all
gather_facts: no
tasks:
- debug:
msg: "{{ london.0.nodename }}"
vars:
- london:
- nodename: music0
- card: Headphone
- mixer: Hardware
给出:
PLAY [all] *******************************************************************************************************
TASK [debug] *****************************************************************************************************
ok: [localhost] => {
"msg": "music0"
}
PLAY RECAP *******************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
现在为什么不用说
0.london.0.nodename
,你会问?
vars
不期望一个列表而是一个字典,而 Ansible 对你太客气了,把它当作字典。
关于ansible - 使用 "bracket notation"索引变量并不总是在 ansible 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65148619/
我们使用 Ө-notation 来写插入排序的最坏情况运行时间。但是我无法将 Ө-notation 的属性与插入排序联系起来,为什么 Ө-notation 适用于插入排序。对于所有 n>=n0,插入排
我最近有幸学习了一点 Idris,我发现非常方便的一件事是 ! -notation ,这让我缩短了 do block 中的一元代码,例如 a' = 7.10)我们可以写 someFunction a
我试图理解 Big Theta 符号并遇到了一个例子: 我知道我们必须为这个符号找到两个常量 c1 和 c2,使得 c1*g(n)<= f(n) <= c2*g(n)。我的问题是他们如何找到这两个常量
我希望它的计算结果为 3,但得到了一个错误: Idris> :let x = Just 2 Idris> 1 + !x (input):1:3-4:When checking an applicati
这个问题已经有答案了: Accessing nested JavaScript objects and arrays by string path (45 个回答) 已关闭 5 年前。 我有一个像这样
Dev Bootcamp 的作业前练习之一是 RPN 计算器。我成功了,但想要重构反馈。非常感谢任何有助于使此代码更清晰的帮助。 class RPNCalculator def evaluate(
素描documentation据说点号和大括号符号可以相互混合。它甚至是一个 example可用: [[context.document currentPage] deselectAllLayers]
如何将这些 CocoaScript“大括号表示法”转换为 JavaScript“点表示法”语法? [fileManager createDirectoryAtPath: tmpFolder withI
只是想知道,例如在维基百科页面 Dijkstra's algorithm O(|E| + |V|log|V|) 中绝对值条的含义是什么 最佳答案 竖线表示 cardinality (或大小)一组。在
我正在处理一个使用系统匈牙利符号的遗留 COM C++ 项目。因为它是对遗留代码的维护,所以约定是以它编写的原始样式进行编码 - 我们的新代码不是这样编码的。所以我对改变这个标准或讨论我们过去的罪不感
我想在 Haskell 中按顺序组合两个 monad Action ,丢弃第二个产生的任何值,并将参数传递给这两个 Action 。目前我正在使用这样的do-block: ask = do res
如何将负数从中缀转换为后缀? 假设我有一个表达式 a = - b - (-c-d) 在我读到的某些地方,您可以将负数归为一类,例如 a = (-b) - (-c-d) 但在这里,如果我这样做,我会在后
我想知道是否有办法使用 2 个堆栈一次性解决中缀表达式?堆栈可以一个用于运算符,另一个用于操作数... shunt-yard算法求解的标准方法是将中缀表达式转换为后缀表达式(反向波兰)然后求解。我不想
我的任务是将一些 Python 代码转换为 Java。我遇到了一些我不熟悉的符号,似乎找不到任何信息。我猜这是因为我缺少关键字。 为了简单起见,我对代码进行了清理并硬编码了一些基本值。 index_t
我想知道是否有一种方法可以使用 2 个堆栈一次解决中缀表达式?堆栈可以是一个用于运算符,另一个用于操作数... shunt-yard算法求解的标准方法是将中缀表达式转换为后缀(逆向抛光),然后求解。我
do 表示法允许我们在没有过多嵌套的情况下表达 monadic 代码,因此 main = getLine >>= \ a -> getLine >>= \ b -> put
我正在学习 Haskell。 我正在尝试查找列表中的元素 as列表元素的总和 bs ,将元素作为元组返回: findSum2 :: [Int] -> [Int] -> [(Int,Int,Int)]
这个问题在这里已经有了答案: How to pass Scala array into Scala vararg method? (3 个回答) What does `:_*` (colon unde
我经常在教程中看到 m_ 前缀用于变量 (m_World,m_Sprites,...) 、示例等主要与游戏开发相关的代码。 为什么人们要给变量添加前缀m_? 最佳答案 这是定义作为成员变量的变量的典型
这个问题在这里已经有了答案: What is a non-capturing group in regular expressions? (17 个回答) 5年前关闭。 对于我的一门课,我必须描述以下
我是一名优秀的程序员,十分优秀!