1

I didn't find the ansible.log on the server. Isn't it enable log by default?

I found if set this in the ansible.cfg, it's true it will save log file on the system

log_path = /var/log/ansible.log

Another, is it possible to save execute state logging on the target server? Such as Terraform's state file to save what ansible had did on the target server. Or if Ansible can save these state on its server, it's better.

I found this setting in the ansible.cfg:

no_target_syslog = False
U880D
  • 8,601
  • 6
  • 24
  • 40
uotn
  • 27
  • 6

1 Answers1

0

Regarding your question

I didn't find the ansible.log on the server. Isn't it enable log by default?

you may have a look into Logging Ansible output.

By default Ansible sends output about plays, tasks, and module arguments to your screen (STDOUT) on the control node. If you want to capture Ansible output in a log, you have three options ...

Regarding your question

Is it possible to save execute state logging on the target server?

technically yes. But you would need to implement something by yourself. You could use the following approach in your playbooks

vars:
  ROLE: "{{ playbook_dir.split('/')[4] }}"
  TASK: "main"

- name: "Make sure there is a log directory for this role {{ ROLE }} and task {{ TASK }}"
  file:
    path: "/var/log/ansible/{{ ROLE }}/{{ TASK }}"
    state: directory

- name: "Log applying role {{ ROLE }} and task {{ TASK }} with {{ ansible_run_tags }}"
  lineinfile:
    path: "/var/log/ansible/{{ ROLE }}/{{ TASK }}/lastexecution.{{ lookup('pipe', 'date +%Y%m%d') }}.log"
    create: yes
    line: "{{ lookup('pipe', 'date') }}, {{ ansible_run_tags }}, {{ ansible_user }}"

The date lookup can also be replaced by an Ansible fact.

U880D
  • 8,601
  • 6
  • 24
  • 40
  • 1
    Thank you very much for your answer and editing. On the managed node, I mean if set `no_target_syslog` in the `ansible.cfg`, it can write ansible related operation in the managed node's syslog, right? I read [Logging Ansible output](https://docs.ansible.com/ansible/latest/reference_appendices/logging.html) the second option, it seems `syslog_facility` is also necessary. – uotn Dec 29 '21 at 00:57