小编Lui*_*dez的帖子

有没有办法检查 ansible 任务中未定义字典键?

所以在我的代码中我有一个任务

- name: cool task
  shell: 'touch iamnotcool.txt'
  when: me.cool is not defined
Run Code Online (Sandbox Code Playgroud)

我的 vars 看起来像

---
me:
  stumped: yes
Run Code Online (Sandbox Code Playgroud)

因此,当我运行任务时,它会返回以下错误

{"failed": true, "msg": "The conditional check 'me.cool' failed. The error was: error while evaluating conditional (me.cool): 'dict object' has no attribute 'cool'.
Run Code Online (Sandbox Code Playgroud)

conditional ansible ansible-playbook

31
推荐指数
2
解决办法
6万
查看次数

有没有办法在ansible中查看主机可用的group_vars,host_vars等?

所以我刚刚成立了一家新公司,在熟悉 ansible 存储库的同时,我想知道是否有任何方法可以在一个地方查看来自 group_vars、host_vars 和所有这些的变量,收集所有这些变量并非易事关于主机的事实。例如,如果我有一个主机文件,如

[foo:children]
bar

[bar]
baz
Run Code Online (Sandbox Code Playgroud)

所以我有两个 group_vars 文件 foo.yml

---
app: kyle
Run Code Online (Sandbox Code Playgroud)

和 bar.yml

---
env: prod
Run Code Online (Sandbox Code Playgroud)

然后我有一个 host_vars 文件 baz.yml

---
type: app-server
Run Code Online (Sandbox Code Playgroud)

有什么办法可以得到如下输出:

Host: baz
app = kyle
env = prod
type = app-server
Run Code Online (Sandbox Code Playgroud)

我已经查看了 setup 模块,但是当我运行ansible all -m setup它时,它返回了所有ansible_*变量,但没有返回我定义的变量。

configuration configuration-management ansible ansible-playbook

7
推荐指数
1
解决办法
4976
查看次数