是什么导致事实变得不可用?
What causes facts to become unavailable?
是什么导致事实在剧本中变得不可用?我正在尝试访问 Ansible 的 ansible_date_time
事实,但我似乎无法弄清楚如何访问它。在 之后,它应该可以简单地在剧本中使用,例如:
---
# 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
ansible.cfg 文件包含用于收集事实的设置。
文档在这里:gathering
implicit
是默认值,将收集事实。
explicit
将改变行为。
这两个设置都可以在剧本中被覆盖。
是什么导致事实在剧本中变得不可用?我正在尝试访问 Ansible 的 ansible_date_time
事实,但我似乎无法弄清楚如何访问它。在
---
# 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
ansible.cfg 文件包含用于收集事实的设置。
文档在这里:gathering
implicit
是默认值,将收集事实。
explicit
将改变行为。
这两个设置都可以在剧本中被覆盖。