# bulk set\_fact from output of an external script?

**URL:** <https://forum.ansible.com/t/bulk-set-fact-from-output-of-an-external-script/29128>\
**Category:** Ansible Project\
**Created:** [November 27, 2018, 4:59pm UTC](https://forum.ansible.com/t/bulk-set-fact-from-output-of-an-external-script/29128 "2018-11-27T16:59:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Spitzer](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@Alexander\_Spitzer](https://forum.ansible.com/u/Alexander_Spitzer)\
**Post date:** [November 27, 2018, 4:59pm UTC](https://forum.ansible.com/t/bulk-set-fact-from-output-of-an-external-script/29128/1 "2018-11-27T16:59:56Z")

</div>

Right now I have a role/common that does a lot of “discovery” about the machine.  
It does things like looks at the hostname and sets “machine\_env” to dev/qa/prod.  
It also does a lot of discovery to see what applications are installed and/or running on the box and then sets facts like “systemd\_nginx\_enabled: true” if nginx is enabled in systemd.  
This all works fine, but there are like 30 checks that I am doing (for all the different apps etc) and it seems to add like 20m+ to the ansible run when I have a lot of machines.

It seems like it would be WAY more efficient to write a script that would quickly do the machine discovery and then output something like:  
machine\_env: prod

systemd\_nginx\_enabled: true  
systemd\_mongodb\_enabled: false

systemd\_redis\_enabled: false

systemd\_consul\_enabled: true

systemd\_apache\_enabled: false

systemd\_zookeeper\_enabled: false  
…

where the output could be iterated over and the respective facts are then set.

Is this possible? I am thinking it is some incantation with “map” and “list”, but I don’t know exactly how to do it.

Thanks!

---

<div class="post-metadata">

**Author:** ![Alexander\_Spitzer](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@Alexander\_Spitzer](https://forum.ansible.com/u/Alexander_Spitzer)\
**Post date:** [November 27, 2018, 7:22pm UTC](https://forum.ansible.com/t/bulk-set-fact-from-output-of-an-external-script/29128/2 "2018-11-27T19:22:51Z")

</div>

[https://docs.ansible.com/ansible/latest/modules/setup\_module.html](https://docs.ansible.com/ansible/latest/modules/setup_module.html)

looks like I can put scripts in /etc/ansible/facts.d on each machine (via ansible) and make the output look something like

----- CUT -----

{  
“machine\_env” : “prod”

…

“systemd\_zookeeper\_enabled” : “false”  
}

----- CUT -----
