Ansible 集合事实不集合可解事实?

Ansible 集合事实不集合可解事实?,ansible,Ansible,在test.yml中,我有 - set_fact: hosts__test='2' - debug: msg='ansible_facts={{ansible_facts}}' 当我执行游戏时,我得到 TASK [test : set_fact] *************************************************************************************** ok: [t2] => {"ansible_facts&

test.yml
中,我有

- set_fact: hosts__test='2'

- debug: msg='ansible_facts={{ansible_facts}}'
当我执行游戏时,我得到

TASK [test : set_fact] ***************************************************************************************
ok: [t2] => {"ansible_facts": {"etc_hosts__test": "2"}, "changed": false}

TASK [test: debug] ******************************************************************************************
ok: [t2] => {
    "msg": "ansible_facts={}"
}

为什么不将
hosts\u test
事实添加到
ansible\u facts
字典中?

当您为主机设置事实时,可以通过
hostvars
访问这些变量

您需要运行:

 - debug: var=hostvars['hostname']['hosts__test']
就你而言:

- debug: var=hostvars['t2']['hosts__test']