Ansible 的默认日志路径在哪里,是否可以在远程服务器上记录操作?
Where is Ansible's default log path and is it possible to log operation on remote server?
我没有在服务器上找到 ansible.log
。不是默认开启log吗?
我发现如果在 ansible.cfg
中设置它,它确实会在系统上保存日志文件
log_path = /var/log/ansible.log
另外,是否可以在目标服务器上保存执行状态日志记录?比如 Terraform 的状态文件,用来保存 ansible 在目标服务器上做了什么。或者如果 Ansible 可以将这些状态保存在它的服务器上,那就更好了。
我在 ansible.cfg
中找到了这个设置:
no_target_syslog = False
关于你的问题
I didn't find the ansible.log
on the server. Isn't it enable log by default?
你可以看看 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 ...
关于你的问题
Is it possible to save execute state logging on the target server?
技术上是的。但是你需要自己实现一些东西。您可以在剧本中使用以下方法
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 }}"
日期查找也可以是。
我没有在服务器上找到 ansible.log
。不是默认开启log吗?
我发现如果在 ansible.cfg
中设置它,它确实会在系统上保存日志文件
log_path = /var/log/ansible.log
另外,是否可以在目标服务器上保存执行状态日志记录?比如 Terraform 的状态文件,用来保存 ansible 在目标服务器上做了什么。或者如果 Ansible 可以将这些状态保存在它的服务器上,那就更好了。
我在 ansible.cfg
中找到了这个设置:
no_target_syslog = False
关于你的问题
I didn't find the
ansible.log
on the server. Isn't it enable log by default?
你可以看看 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 ...
关于你的问题
Is it possible to save execute state logging on the target server?
技术上是的。但是你需要自己实现一些东西。您可以在剧本中使用以下方法
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 }}"
日期查找也可以是