是什么导致事实变得不可用?

时间:2015-07-15 14:46:51

标签: ansible ansible-facts

是什么导致事实在剧本中变得不可用?我试图访问Ansible的ansible_date_time事实,但我似乎无法弄清楚如何访问它。在Ansible date variable之后,它应该只在一个剧本中提供,例如:

---
# 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

1 个答案:

答案 0 :(得分:1)

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