1

I would like to log on the remote host each time an ansible-generated script was run. Ideally, I would like to see the full ansible command that was run. At a minimum it should log the time and which playbook was run.

I would like a history on each host when changes were made with Ansible.

Is there a reasonable way to do this?

rwfbc
  • 900
  • 1
  • 10
  • 22
  • 1
    Are you aware that ansible -- by default, as far as I know -- logs commands to syslog (or the systemd journal)? – mdaniel Jun 06 '19 at 03:48
  • @Matthew: No, I was not aware of the default logging. However, I had checked the syslog and looked at journalctl, and did not find any ansible logs. I am using ansible 2.7.7 on Ubuntu 16.04. How is the logging configured? What would such logs look like (I grep'ed for "ansible"). – rwfbc Jun 06 '19 at 18:44
  • 1
    An example line from one of my machines: `Jun 07 00:13:51 ip-10-0-1-119 ansible-apt[5317]: Invoked with dpkg_options=force-confdef,force-confold autoremove=False force=False force_apt_get=False policy_rc_d=None package=['awscli', 'curl', 'ebtables', 'ipvsadm', 'jq', 'socat'] autoclean=False install_recommends=None name=['awscli', 'curl', 'ebtables', 'ipvsadm', 'jq', 'socat'] purge=False allow_unauthenticated=False state=present upgrade=None update_cache=None default_release=None only_upgrade=False deb=None cache_valid_time=0` (`journalctl -o verbose` says `SYSLOG_IDENTIFIER=ansible-apt`) – mdaniel Jun 07 '19 at 05:41
  • 1
    Relevant: https://stackoverflow.com/questions/40913619/how-do-i-read-understand-ansible-logs-on-target-host-written-by-syslog – mdaniel Jun 07 '19 at 05:42

1 Answers1

0

My problem was that logging on the remote host was disabled. The documentation states that the default is logging enabled. So it must have been disabled in the example config we started from.

I had to change no_target_syslog to false in ./config/ansible.cfg.

# TODO Deprecated option ?
# no_target_syslog = True
no_target_syslog = False
rwfbc
  • 900
  • 1
  • 10
  • 22