1

是什么导致事实在剧本中变得不可用?我正在尝试访问 Ansible 的ansible_date_time事实,但我似乎无法弄清楚如何访问它。在Ansible date variable之后,它应该可以简单地在 playbook 中使用,例如:

---
# test.yml
- hosts: localhost
  tasks:
    - debug: var=ansible_date_time

当运行为:

ansible-playbook test.yml

应该产生输出:

PLAY [localhost] **************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug var=ansible_date_time] *******************************************
ok: [localhost] => {
    "ansible_date_time": {
        "date": "2015-07-09",
        "day": "09",
        "epoch": "1436461166",
        "hour": "16",
        "iso8601": "2015-07-09T16:59:26Z",
        "iso8601_micro": "2015-07-09T16:59:26.896629Z",
        "minute": "59",
        "month": "07",
        "second": "26",
        "time": "16:59:26",
        "tz": "UTC",
        "tz_offset": "+0000",
        "weekday": "Thursday",
        "year": "2015"
    }
}

PLAY RECAP ********************************************************************
localhost      : ok=2    changed=0    unreachable=0    failed=0

但是,当我运行剧本时,我收到:

PLAY [localhost] ************************************************************** 

TASK: [debug var=ansible_date_time] ******************************************* 
ok: [localhost] => {
    "var": {
        "ansible_date_time": "ansible_date_time"
    }
}

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

什么会导致ansible_date_time不可用?


更新:内容/etc/ansible/ansible.cfg是:

[defaults]
sudo_user=root
gathering=explicit
4

1 回答 1

1

ansible.cfg 文件包含收集事实的设置。
文档在这里:收集
implicit是默认设置,将收集事实。
explicit会改变行为。
这两个设置都可以在剧本中被覆盖。

于 2015-07-16T19:23:52.620 回答