Doing a diff between two device's facts

Hi,

I have a single playbook using one module to gather facts about ONE device and this works all good. Upon execution, I register a variable and display several debug messages. All good. I added a second host to the hosts file and I’m now getting good debug info on both devices.

My next task is to compare, or do a diff, on particular fact data from each device. This diff would happen by sending both variables (facts) to another custom module to analyze. I was going to do a single host per playbook and pass the registered variable to a 3rd playbook, but variables are only valid within the pb. As an alternative, I suppose I can write the contents of the registered variable to a file in the first pb and the read from that in the second playbook, then do the needed comparisons, but that just doesn’t seem right.

While this scenario is for custom facts, the same solution should hold true for the off the shelf facts too.

What would be the best approach for this? Any feedback would be greatly appreciated.

Thanks,
Jason

If you have a single play to gather facts on all hosts you can then have a second play within the same playbook that compares the facts for different hosts… This would work for runs with small numbers of hosts but might get a lot harder for larger quantities of hosts.

http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

You could take the first host and assume that it is definitive and then walk through all of the other hosts comparing the facts that you care about and saying which ones differ. This would work for two hosts, and might work for more but if the odd one out was the first host then you would get a list of all other hosts as differing.

I hope that this helps,

Adam

I’ve used “ansible -m setup -t ./tmp hosts” then used diff on the output json files (with a little vim magic reformatting).​

Okay, got it. Have it working now. Just need to decide how I want to do diffs and/or analyze the data!

Thanks!
Jason

Thanks, Brian. Have an alternative solution working now. May try this one later too.

Thanks for the response.

secrets don't make friends! mind closing the loop by sharing what you came
up with?

Hmm, if you are trying to build a “how are these various servers different” kind of solution in Ansible, I’ll say that doesn’t really exist yet, so what you are going to create if attempting to use ansible as a programming language (it’s not) may feel a little hackish.

Brent, sorry! Here is what I have working right now.
Michael et al, feel free to comment on this “hack” and let me know what else could be done to simplify.

If you’re trying to make ansible make reports, rather than doing the debug calls, maybe you would want to make a template for the report instead.

Just a thought…

Great suggestion. Templates will work great for storing the results. Displaying them in real-time may still be beneficial.

Thanks.