1

I am running Playbook to install in-house software on Windows target machines. I am printing a log of "msg" during this process so that I can forward that to QA / compliance team. However, I do not know how to generate a log file with output from debug > "msg" and place it on Windows host machine. I know log_plays might be useful, but I could not find any example on how to actually use that module.

Any example code would be appreciated.

user11137977
  • 13
  • 1
  • 5
  • Hi user11137977, welcome to SO. Are you already aware of [ara](https://ara.recordsansible.org/), which is really closer to the intent of your question – mdaniel Apr 19 '19 at 01:06
  • Thanks Matthew, while ARA looks good, I was really hoping to get some solution within Ansible, which might not need any additional installation. – user11137977 Apr 19 '19 at 01:29

2 Answers2

4

So, regrettably, /var/log/ansible/hosts is hardcoded but otherwise it should behave as you would expect. You can enable the callback via ansible.cfg or the $ANSIBLE_STDOUT_CALLBACK environment variable:

env ANSIBLE_STDOUT_CALLBACK=log_plays ansible-playbook -i host1,host2 the_file.yml

Be aware that ad-hoc mode does not load callback plugins, so you need to request that explicitly:

env ANSIBLE_LOAD_CALLBACK_PLUGINS=yes ANSIBLE_STDOUT_CALLBACK=log_plays \
    ansible -i host1,host2 -m ping '*'

If the /var/log/ansible/hosts part bugs you, there is also $ANSIBLE_LOG_PATH which will cause ansible to carbon-copy the log output to a file, and it works fine in ad-hoc mode:

env ANSIBLE_LOG_PATH=$PWD/my-log ansible -i host1,host2 -m ping '*'
mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • Thanks Matthew, is there a way to set ANSIBLE_LOG_PATH through playbook or task? – user11137977 Apr 19 '19 at 23:58
  • @user11137977 I don't think so, as that would be chicken and egg trying to configure the plugins needed for the playbook. If it wasn't clear, that environment variable is only one way to configure that setting: the pages I linked to describe the `ansible.cfg` values that you can set and check into source control next to your playbook to have them take effect all the time – mdaniel Apr 21 '19 at 18:05
1

Probably a bit late, but you can add log_path=mylogfile to your ansible.cfg file in the defaults section

See in the link provided in the answer above.

  • Thanks for the input. One of the problems, I was running into was that my ansible.cfg was not configured correctly. I was able to fix that through the link above. – user11137977 Oct 01 '19 at 00:21