# Use cases for set\_fact instead of defining vars

**URL:** <https://forum.ansible.com/t/use-cases-for-set-fact-instead-of-defining-vars/24481>\
**Category:** Ansible Project\
**Created:** [May 13, 2017, 8:42pm UTC](https://forum.ansible.com/t/use-cases-for-set-fact-instead-of-defining-vars/24481 "2017-05-13T20:42:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Listing](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@Listing](https://forum.ansible.com/u/Listing)\
**Post date:** [May 13, 2017, 8:42pm UTC](https://forum.ansible.com/t/use-cases-for-set-fact-instead-of-defining-vars/24481/1 "2017-05-13T20:42:49Z")

</div>

Hi,

You have set\_fact and the ability to set vars, but when should one use set\_fact? In the ansible-doc I see the following example, but when setting ‘one\_fact’, what is the benefit instead of defining a var? Wouldn’t it be possible to define vars per host as well? I hope someone can explain me when it would be really useful to use the set\_fact module. Is it purely to be able to dynamically perform actions per host based on system vars?

- set\_fact:  
one\_fact: something  
other\_fact: “{{ local\_var \* 2 }}”  
another\_fact: “{{ some\_registered\_var.results | map(attribute=‘ansible\_facts.some\_fact’) | list }}”
