Connect to a list of Cisco devices (switches + router) and pull facts from the devices (S/N, interfaces,…)
Create a report with each fact’s devices in a CSV file
For the 1st point I’m currently writing a new module based on Exscript that connects to the device, issue some show commands, parse the output and create some facts based on those outputs.
For the 2nd point I was thinking of a callback plugin using the on_stats methods. Indeed the on_stats method is called at the end of the playbook.
Unfortunately, I don’t understand from the ansible code how facts are created and where in the playbook they are avalaible.
Is it possible to retrieve facts at the end of the playbook for all hosts reachable ?
Thanks for your answer ! It works great for variables but as far as I tested it doesn’t get facts out.
I ran a setup module which pull down a lot of fact from a linux box but those facts are not in get_variables().
Nevertheless I will investigate on this little issue.
Just dumping a templated file to the local filesystem that contains what you want to see, and saying “go read output.txt” for the results, versus writing a custom callback plugin.
One more question regarding callback. We are currently looking to developp different callback in order to stock facts/vars in CSV & in database. This means we will create 2 callbacks.
I’d like to know if there is any way to enable one/several callback from a playbook variable ? Does Ansible ship with such feature ?
An example will be that all callbacks will have their disabled attribute set to False, then the playbook could read a specific attribute and activate only specific callback based on this attribute.
Your callback could decide to set a “self.active = True/False” in the constructor, and each method could return “if not self.active” to basically no-op.
The callback interface isn’t really going to see much of those variables directly, unless you jump through some hoops that may not be part of a stable API.
You might want to consider making it learn from an environment variable, depending on the use case.