Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`with_items` output is too verbose

I wrote an ansible task to iterate over a list of settings using with_items. Now all my settings are logged when I run ansible. It is very verbose and makes it hard to see what is happening. But, if I disable all the output with no_log, I will have no way to identify specific items when they fail.

How could the output be improved — to show only an identifier for each item?

Example task:

- authorized_key:
    user: "{{ item.user }}"
    key: "{{ item.key }}"
  with_items: "{{ ssh_keys }}"

Example output:

TASK [sshkey-alan-sysop : ssh authorized keys] ********************************* 

ok: [brick] => (item={u'user': u'alan-sysop', u'key': u'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAgRe16yLZa8vbzsrxUpT5MdHoEYYd/awAnEWML4g+YoUvLDKr+zwmu78ze/E1NSipoZejXpggUYRVhh8MOiCX6qpUguBDWZFlvSCE/7uXWWg7Oht0f1kDS2xU7YiycPIzMN1dmUEFY9AixnN936Dq6nOtEzgBwjo66I1YC/5jrsQEqF19shx43A4DTFlPUz/PnsqHl2ESrkIk3e8zyidaPN2pRbA5iKzdvPW4E2W2tKw9ll40vqRXzaWIF7v293Ostwi1IPi2erlC777DhjZUhZ1VGXIR7FDAfANzalrMe6c/ZysiXewiUYgMw0I8Dh1LK3QMj9Kuo35S5E0Xj3TB alan-sysop@alan-laptop'})
like image 225
sourcejedi Avatar asked Mar 16 '17 11:03

sourcejedi


2 Answers

There's loop_control for that:

- authorized_key:
    user: "{{ item.user }}"
    key: "{{ item.key }}"
  with_items: "{{ ssh_keys }}"
  loop_control:
    label: "{{ item.user }}"
like image 58
Konstantin Suvorov Avatar answered Oct 22 '22 02:10

Konstantin Suvorov


The identifiers can be used as keys of a dictionary.

- authorized_key:
    user: "{{ item }}"
    key: "{{ ssh_keys[item] }}"
  with_items: "{{ ssh_keys.keys() }}"

Example output:

TASK [sshkey-alan-sysop : ssh authorized keys] *********************************
ok: [brick] => (item=alan-sysop)
like image 1
sourcejedi Avatar answered Oct 22 '22 03:10

sourcejedi