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?