I've just write the Ansible config to keep my ansible.log
at one logline per action.
[defaults]
log_path = /var/log/ansible.log
nocows=true
stdout_callback=ansible.builtin.oneline
host_key_checking = false
inventory = /test/ansible/hosts.txt
It works perfectly with the ansible-playbook
command.
But if I want to execute that command
ansible all -m ping
I will get the multi-line record in the log file.
2024-11-08 10:12:41,689 p=1164 u=root n=ansible | node1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.10"
},
"changed": false,
"ping": "pong"
}
So I have to always add the -o
option for non-playbooks commands
ansible all -m ping -o
to get my cozy oneline log
2024-11-08 10:15:47,895 p=1181 u=root n=ansible | node1 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3.10"},"changed": false,"ping": "pong","warnings": ["..."]}
My question is "How to make Ansible always uses the -o
flag in any command?" Is it possible in general?
Also merge ANSIBLE_LOAD_CALLBACK_PLUGINS into your configuration:
It is a quirk of the ansible ad-hoc program that its callback is minimal, oneline with that -o option, or requires this config option to respect callback in configuration.
Callback plugins are always loaded for ansible-playbook.