bulk set_fact from output of an external script?

10 views
Skip to first unread message

Alexander Spitzer

unread,
Nov 27, 2018, 11:59:56 AM11/27/18
to Ansible Project
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!

Alexander Spitzer

unread,
Nov 27, 2018, 2:22:52 PM11/27/18
to Ansible Project
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 -----
Reply all
Reply to author
Forward
0 new messages