是什么导致事实在剧本中变得不可用?我正在尝试访问 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