Reputation: 10566
Using ansible with logging enabled is useful for auditing the history of actions taken on a server. I argue it is also important to indicate why a specific changes is made.
In playbooks, I can use the name
keyword to describe what a change is and why it is done. However, I need help finding a way to include a description of actions taken when running ansible via ad-hoc commands.
Ideally, there would be a --name
option, then I could do this:
ansible webservers -a "shutdown -r now" --name "Restarting webservers to load updated kernels"
Or perhaps, if I could run two ad-hoc commands at once, I could include a debug msg:
ansible webservers -a "shutdown -r now" -m debug -a "msg='Restarting webservers to load updated kernels'"
Is there any way to have a comment logged by ansible when running an ad-hoc command?
Edit: I just realize the specific commands executed ad-hoc aren't logged, e.g., running ansible -v all -a "date"
prints the output of date
to the log, but not the command itself:
2022-05-15 14:20:23,991 p=67807 u=q n=ansible | 1.2.3.4 | CHANGED | rc=0 >>
Sun 15 May 2022 07:20:23 PM UTC
Any way to get ansible to log the command itself that is run?
Upvotes: 1
Views: 682
Reputation: 39264
There is no possibility to pass a name to an ad-hoc command, and, this way of running Ansible is meant for a single module to be run, so, no, you won't be able to add a debug message in.
This said, in your specific use case, you could probably use the optional wall
message that shutdown
allow you to add in order to have an indication of the reason why those nodes where rebooted:
ansible webservers \
-a "shutdown -r now 'Restarting webservers to load updated kernels'"
Upvotes: 2