Ansible - Getting Started with Logs (log_path)

By default, the default Ansible configuration file (/etc/ansible/ansible.cfg) has log_path commented out, like this.

#log_path = /var/log/ansible.log

 

When commented out, Ansible will log events to the machines syslog (system log daemon). As an example, syslog may write Ansible events to the /var/log/messages file.

Mar 22 12:55:08 [localhost] ansible-command: Invoked with creates=None executable=None _uses_shell=True strip_empty_ends=True _raw_params=ping -c4 was2.software.eng.us removes=None argv=None warn=True chdir=None stdin_add_newline=True stdin=None

 

There are a number of ways to configure Ansible to log events to a custom log file, where the higher option in this list will take precedence over the lower options.

  1. ANSIBLE_LOG_PATH variable
  2. log_path in ansible.cfg in the present working directory
  3. log_path in .ansible.cfg in the user home directory (e.g. /home/john.doe/.ansible.cfg)
  4. log_path in /etc/ansible/ansible.cfg

 


ANSIBLE_LOG_PATH variable

Here is how you could set a temporary log path using the ANSIBLE_LOG_PATH variable. Or, you can include this in your users hidden .bash_profile file (e.g. /home/john.doe/.bash_profile) to make this setting permanent.

export ANSIBLE_LOG_PATH=/home/john.doe/ansible.log

 


log_path directive

Define the log_path directive in your Ansible configuration file (ansible.cfg), where the higher option in this list will take precedence over the lower options.

  1. log_path in ansible.cfg in the present working directory
  2. log_path in .ansible.cfg in the user home directory (e.g. /home/john.doe/.ansible.cfg)
  3. log_path in /etc/ansible/ansible.cfg

In this example, Ansible will start to log events to /var/log/ansible.log.

log_path = /var/log/ansible.log

 

AVOID TROUBLE

If you are using your own ansible.cfg file (e.g. /home/john.doe/ansible.cfg) instead of the global /etc/ansible/ansible.cfg file, the log_path directive must be under the [defaults] header.

 


Create and rotate the log file

You may need to create the log file and update the permission so that it has the write permission for user, group and other. You may want to also configure logrotate to rotate the log files.

touch /var/log/ansible.log
chmod 0666 /var/log/ansible.log

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 75470 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |