【发布时间】:2019-06-03 17:06:08
【问题描述】:
我正在尝试通过复制到单个主机的文件来审核我的系统。默认输出非常详细。我只想查看 Ansible 日志输出的相关字段;这样,超过 1000 台主机,我可以更快地解决我的问题。 .当我的游戏成功时,我只想看看:
ok: u'/mnt/inventory/hostname999'
我有一个如下所示的剧本:
- hosts: 'localhost'
name: Playbook for the Audit for our infrastructure.
gather_facts: False
become: no
connection: local
roles:
- { role: network, tags: network }
我的网络角色 main.xml 文件如下所示:
---
- name: find matching pattern files
find:
paths: "/mnt/inventory"
patterns: "hostname*"
file_type: directory
register: subdirs
- name: check files for net.ipv4.ip_forward = 0
no_log: False
lineinfile:
name: "{{ item.path }}/sysctl.conf"
line: "net.ipv4.ip_forward = 0"
state: present
with_items: "{{ subdirs.files }}"
register: conf
check_mode: yes
failed_when: (conf is changed) or (conf is failed)
- debug:
msg: "CONF OUTPUT: {{ conf }}"
但我得到这样的日志输出:
ok: [localhost] => (item={u'uid': 0, u'woth': False, u'mtime': 1546922126.0,
u'inode': 773404, u'isgid': False, u'size': 4096, u'roth': True, u'isuid':
False, u'isreg': False, u'pw_name': u'root', u'gid': 0, u'ischr': False,
u'wusr': False, u'xoth': True, u'rusr': True, u'nlink': 12, u'issock':
False, u'rgrp': True, u'gr_name': u'root', u'path':
u'/mnt/inventory/hostname999', u'xusr': True, u'atime': 1546930801.0,
u'isdir': True, u'ctime': 1546922126.0, u'wgrp': False, u'xgrp': True,
u'dev': 51, u'isblk': False, u'isfifo': False, u'mode': u'0555', u'islnk':
False})
此外,我的 CONF OUTPUT 调试消息从未显示,我不知道为什么不显示。
我查看了 https://github.com/ansible/ansible/issues/5564 和其他文章,但它们似乎只是指诸如 shell 命令之类的项目,这些项目将内容发送到标准输出,而 lineinfile 没有。
【问题讨论】:
标签: ansible