1.

How is the Ansible set_fact module different from vars, vars_file, or include_var?

Answer»

 In Ansible, set_fact is used to SET new variable values on a host-by-host basis which is just like ansible facts, discovered by the setup module. These variables are AVAILABLE to subsequent plays in a playbook. In the case of vars, vars_file, or include_var we know the value beforehand whereas when using set_fact, we can STORE the value after preparing it on the fly using certain tasks like using FILTERS or taking subparts of another variable. We can also set a fact cache over it.

set_fact variable assignment is done by using key-pair values where the key is the variable name and the value is the assignment to it. A simple example will be like below

- set_fact:one_fact: value1second_fact:value2


Discussion

No Comment Found