我使用工作流程,并希望将一些变量传递给下一个模板。我为此使用set_stats,但似乎它不是按主机传递值。
template1:
- name: set fact
set_stats:
data:
infoblox:
changed: false
ipv4: "{{ host['ipv4addrs'][0]['ipv4addr'] }}"
when: host_record.status is defined and host_record.status == 201
这出戏的输出看起来不错。每个主机都有一个不同的IP。
TASK [set fact] ****************************************************************
ok: [host1] => {"ansible_stats": {"aggregate": true, "data": {"infoblox": {"changed": false, "ipv4": "xxx.xxx.xxx.2"}}, "per_host": false}, "changed": false}
ok: [host2] => {"ansible_stats": {"aggregate": true, "data": {"infoblox": {"changed": false, "ipv4": "xxx.xxx.xxx.4"}}, "per_host": false}, "changed": false}
ok: [host3] => {"ansible_stats": {"aggregate": true, "data": {"infoblox": {"changed": false, "ipv4": "xxx.xxx.xxx.3"}}, "per_host": false}, "changed": false}
template2的输出,该输出在template1之后被调用。在这里您可以看到所有3台主机的IP都相同
TASK [debug] *******************************************************************
ok: [host1] => {
"infoblox": {
"changed": false,
"ipv4": "xxx.xxx.xxx.3"
}
}
ok: [host2] => {
"infoblox": {
"changed": false,
"ipv4": "xxx.xxx.xxx.3"
}
}
ok: [host3] => {
"infoblox": {
"changed": false,
"ipv4": "xxx.xxx.xxx.3"
}
}
然后,我尝试在per_host: true
中使用set_stats
选项,但是由于某种原因,不再设置该变量。我一定做错了事
TASK [debug] *******************************************************************
ok: [host1] => {
"infoblox": "VARIABLE IS NOT DEFINED!"
}
ok: [host2] => {
"infoblox": "VARIABLE IS NOT DEFINED!"
}
ok: [host3] => {
"infoblox": "VARIABLE IS NOT DEFINED!"
}