<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I spoke with other Ansible Core devs to get some clarity on this change.<div class=""><br class=""></div><div class="">This is not a change that is being made quickly, lightly, or without a whole of bunch of reservation. In fact, that PR created by agaffney may not be merged any time soon. He just wanted to get something started and there is still ongoing discussion on that PR. It is definitely a WIP at this point.</div><div class=""><br class=""></div><div class="">The main reason for this change is that pretty much all of the Ansible CVEs to date came from "fact injection", meaning a fact that contains executable Python code Jinja will merrily <font face="Courier New" class="">exec()</font>. Vars, hostvars, and facts are different in Ansible (yes, this is confusing — sorry). All vars go through a templating step. By copying facts to vars, it means facts get templated controller side which could lead to controller compromise if malicious code exists in facts.</div><div class=""><br class=""></div><div class="">We created an AnsibleUnsafe class to protect against this, but stopping the practice of injecting facts into vars would close the door completely. It also alleviates some name collisions if you set a hostvar that has the same name as a var. We have some methods that filter out certain variables, but keeping facts and vars in separate spaces is much cleaner.</div><div class=""><br class=""></div><div class="">This also does not change how hostvars set via <font face="Courier New" class="">set_fact</font> are referenced. (<font face="Courier New" class="">set_fact</font> should really be called <font face="Courier New" class="">set_host_var</font>). Variables set with <font face="Courier New" class="">set_fact</font> are not facts and are therefore not inside the <font face="Courier New" class="">ansible_facts</font> dict. They are in the <font face="Courier New" class="">hostvars</font> dict, which you can reference as <font face="Courier New" class="">{{ my_var }}</font> or <font face="Courier New" class="">{{ hostvars['some-host']['my_var'] }}</font> if you need to look it up from a different host.</div><div class=""><br class=""></div><div class="">All that being said, the setting to control this behavior as Emilien pointed out is <font face="Courier New" class="">inject_facts_as_vars</font>, which defaults to <font face="Courier New" class="">True</font> and will remain that way for the foreseeable future. I would not rush into changing all the fact references in playbooks. It can be a gradual process.</div><div class=""><br class=""></div><div class="">Setting <span style="font-family: "Courier New";" class="">inject_facts_as_vars </span>to<span style="font-family: "Courier New";" class=""> True </span>means <font face="Courier New" class="">ansible_hostname</font> becomes <font face="Courier New" class="">ansible_facts.hostname</font>. You do not have to use the hostvars dictionary — that is for looking up facts about hosts other than the current host.</div><div class=""><br class=""></div><div class="">If you wanted to be proactive, you could start using the <font face="Courier New" class="">ansible_facts</font> dictionary today since it is compatible with the default setting and will not affect others trying to use playbooks that reference <font face="Courier New" class="">ansible_facts</font>.</div><div class=""><br class=""></div><div class="">In other words, with the default setting of <font face="Courier New" class="">True</font>, you can use either <font face="Courier New" class="">ansible_hostname</font> or <font face="Courier New" class="">ansible_facts.hostname</font>. Changing it to <font face="Courier New" class="">False</font> means only <font face="Courier New" class="">ansible_facts.hostname</font> is defined.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">Like, really. I know we can't really have a word about that kind of decision, but... damn, WHY ?!</blockquote><br class=""></div><div class="">That is most certainly not the case. Ansible is developed in the open and we encourage community members to attend <a href="https://github.com/ansible/community/blob/master/meetings/README.md" class="">meetings</a> and add topics to the <a href="https://github.com/ansible/community/issues/325" class="">agenda</a> for discussion. Ansible also goes through a proposal process for major changes, which you can view <a href="https://github.com/ansible/proposals/issues?utf8=%E2%9C%93&q=is:issue+is:open" class="">here</a>.</div><div class=""><br class=""></div><div class="">You can always go to #ansible-devel on Freenode or start a discussion on the <a href="https://groups.google.com/forum/#!forum/ansible-devel" class="">mailing list</a> to speak with the Ansible Core devs about these things as well.</div><div class=""><br class=""></div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">---</div><div class=""><br class=""></div><div class="">Respectfully,</div><div class=""><br class=""></div><div class="">Sam Doran</div><div class="">Senior Software Engineer</div><div class="">Ansible by Red Hat</div><div class=""><a href="mailto:sdoran@redhat.com" class="">sdoran@redhat.com</a></div></div></div></div></div></div></div></body></html>