Ansible - How to set log file path to the customized location?

Hi,
Before triggering the ansible playbook, i have set this export ANSIBLE_LOG_PATH var to redirect all the output to the log file. But the output is not redirected to this new log and its empty.
Are there any approach to redirect the output other than using ansible.cfg which sets at Global level? Pls share your thoughts on this. Appreciate this help.

export ANSIBLE_LOG_PATH=/home/ansadmin/ansible-mar7.log

Thanks
~Saravanan

I just tried with the env var in the environment and also on the command line:

ansible-playbook playbook.yaml -i inventory
ANSIBLE_LOG_PATH=/tmp/ansible.log ansible-playbook playbook.yaml -i inventory
cat /tmp/ansible.log
<logs>
export ANSIBLE_LOG_PATH=/tmp/ansible2.log
ansible-playbook playbook.yaml -i inventory
cat /tmp/ansible2.log
<logs>

Ensure the user has write permissions to the log directory.

I tried the same, but it didnt work for me…

Steps followed:

  1. Commented the log_path parameter in ansible.cfg file
  2. Created the log file /tmp/ansible2.log and gave full permission (chmod 777 /tmp/ansible2.log)
  3. set export var on the terminal → export ANSIBLE_LOG_PATH=/tmp/ansible2.log
  4. ran my playbook yml
  5. i see /tmp/ansible2.log is empty and didnt print any information in it.

Am i missing anything here?

What happens when you run it like this? There is no need to create the logfile, all users have access to /tmp

No, even that didnt work out.

What OS and Ansible version are you using?

Maybe see what is in the debug log. You can do this by adding -vvv (for very verbose) to your ansible-playbook command. Note that this will output to the console, not to the log file.

OS is SUSE linux (SLES12 SP5) .
ansible [core 2.11.12]

i ran my playbook with debug mode. But it didnt show up any useful info about log file path.

ANSIBLE_LOG_PATH=/tmp/ansible.log ansible-playbook testansible.yaml -vvv
ansible-playbook [core 2.11.12]
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.6/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.6.15 (default, Sep 15 2021, 14:20:42) [GCC]
jinja version = 3.0.3
libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Skipping callback ‘default’, as we already have a stdout callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Skipping callback ‘oneline’, as we already have a stdout callback.

PLAYBOOK: testansible.yaml *************************************************************************************************************************************************************
1 plays in testansible.yaml

PLAY [localhost] ***********************************************************************************************************************************************************************
META: ran handlers

TASK [test job] ************************************************************************************************************************************************************************
task path: /home/ansadmin/SHELL_SCRIPT/kernel_vormetric/testansible.yaml:8
ok: [localhost] => {
“msg”: " Test jobs"
}
META: ran handlers
META: ran handlers

PLAY RECAP *****************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

ls -ltr /tmp/ansible.log
ls: cannot access ‘/tmp/ansible.log’: No such file or directory

That is quite an old version of Ansible. Did you install it through the OS package manager? I always recommend people to install ansible through pip.

Yes, i installed ansible via pip only. Is setting log file path in the cmd line not supported in ansible version 2.11.12?

I would upgrade your old version of ansible.

I see next available ansible version is 2.12. Can I go with it?

Where are you seeing that? The current version of ansible is 2.16.4:
ansible-core · PyPI
Releases · ansible/ansible (github.com)