大网数据广告活动
服务器运维问答

Ansible with_items doesn't print whole item?

· 52CE 我爱测

I'm automatically securing SSL keys like this: - name: Find ssl keys find: paths="/etc/ssl/" patterns="*.key" recurse=yes register: secure_ssl_keys_result - name: Secure ssl keys file: path={{ item.path }} user=root group=root mo…

问题原文

原帖链接 · Zulakis · CC BY-SA 4.0

I'm automatically securing SSL keys like this:

- name: Find ssl keys
  find: paths="/etc/ssl/" patterns="*.key" recurse=yes
  register: secure_ssl_keys_result

- name: Secure ssl keys
  file: path={{ item.path }} user=root group=root mode=600
  with_items: secure_ssl_keys_result.files

Now, for every item, there is a huge log message with the whole content of the item:

ok: [127.0.0.1] => (item={u'uid': 0, u'woth': False, u'mtime': 1454939377.264, u'inode': 400377, u'isgid': False, u'size': 3243, u'roth': False, u'isuid': False, u'isreg': True, u'gid': 0, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': False, u'path': u'/etc/ssl/foo.key', u'xusr': False, u'atime': 1454939377.264, u'isdir': False, u'ctime': 1454939657.116, u'isblk': False, u'xgrp': False, u'dev': 65025, u'wgrp': False, u'isfifo': False, u'mode': u'0600', u'islnk': False})

This is incredibly unreadable, as I only want to know the path of the item that is being processed (and maybe changed). With a big number of keys, this get's out of hand really quick.

How can I change this play in a way that only the item.path is being printed out for each item?

I have already tried no_log: True, but this completely omits the output of course.

已采纳解答

原帖链接 · sourcejedi · CC BY-SA 3.0

Ansible 2.2 has loop_control.label for this.

- name: Secure ssl keys
  file: path={{ item.path }} user=root group=root mode=600
  with_items: secure_ssl_keys_result.files
  loop_control:
    label: "{{ item.path }}"

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。