【问题标题】:Undefined variable when running Ansible play运行 Ansible play 时未定义的变量
【发布时间】:2017-01-12 15:42:17
【问题描述】:

我正在运行在 YAML 文件中定义的多个 ansible 播放。

在最后一场比赛中,我收到以下错误:

{"failed": true, "msg": "The conditional check 'ansible_os_family == \"RedHat\"' failed. The error was: error while evaluating conditional (ansible_os_family == \"RedHat\"): 'ansible_os_family' is undefined\n

我需要对收集的事实或ansible.cfg 中的内容进行更改吗?

【问题讨论】:

  • 您能明确添加gather_facts: true 并尝试一下吗?
  • 这似乎奏效了!如果您将其发布为答案,那么我会接受。

标签: ansible ansible-facts


【解决方案1】:

添加:

gather_facts: true

到你的最后一场比赛并尝试。

【讨论】:

  • 也许这已经改变了,因为我不必添加 gather_facts: true 以使条件 when: ansible_os_family == 'RedHat' 工作。但是,如果有一个明确的 gather_facts: false,那么您将收到上面报告的错误。
  • @pforsthoff gather_facts 默认为true。 OP 明确将其设置为 false,因此删除它或将其设置为 true 都可以。
【解决方案2】:

除了@helloV 的回答:

给自己和他人的注释,gathering =gather_facts: 一起使用:

# smart - gather by default, but don't regather if already gathered
# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
# gathering = explicit

【讨论】:

    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2018-04-23
    • 1970-01-01
    • 2022-11-21
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多