4

自动化运维工具Ansible(21)日志回调插件使用

 2 years ago
source link: https://blog.51cto.com/u_15630500/5332310
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

自动化运维工具Ansible(21)日志回调插件使用

原创

内置的回调插件 `log_plays` 会将 playbook 的返回信息输出到 `/var/log/ansible/hosts` 目录中。

[root@localhost ~]# ansible-doc -t callback log_plays
> LOG_PLAYS (/usr/lib/python2.7/site-packages/ansible/plugins/callback/log_plays.py)
This callback writes playbook output to a file per host in the
`/var/log/ansible/hosts` directory

* This module is maintained by The Ansible Community
OPTIONS (= is mandatory):

- log_folderhua
The folder where log files will be created.
[Default: /var/log/ansible/hosts]
set_via:
env: 环境变量方式
- name: ANSIBLE_LOG_FOLDER
ini: 方式
- key: log_folder
section: callback_log_plays
环境变量方式:
[root@localhost ~]# export ANSIBLE_LOG_FOLDER=/tmp/ansible/hosts

配置文件方式:
[root@localhost ~]# vim /etc/ansible/ansible.cfg
[callback_log_plays] //492行
log_folder=/tmp/ansible/hosts/

配置到白名单

callback_whitelist = log_plays

callback_whitelist = timer,log_plays等
[root@localhost home]# ansible all -i hosts -m ping

[root@localhost home]# ls /tmp/ansible/hosts/192.168.19.1
192.168.19.102 192.168.19.104 192.168.19.106 192.168.19.108 192.168.19.110
192.168.19.103 192.168.19.105 192.168.19.107 192.168.19.109
[root@localhost home]# ansible-playbook -i hosts checkhost2.yml

[root@localhost home]# cat /tmp/ansible/hosts/192.168.19.102
May 24 2072 00:38:38 - OK - {"module_args": {"data": "pong"}} => {"changed": false, "ping": "pong", "_ansible_no_log": false}

May 24 2072 00:41:01 - OK - {"ansible_distribution": "CentOS", "changed": false, "_ansible_verbose_always": true, "_ansible_no_log": false}
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK