Count registered results based on pattern

11 views
Skip to first unread message

Tom Paine

unread,
Jul 27, 2015, 2:32:52 PM7/27/15
to Ansible Project
I have a collection of registered shell commands captured and would like to be able to count how many match a pattern:

- name: run a shell command to produce 'a' or 'b' on all boxes and collect the results
  run_once
: true
  shell
: return_a_or_b.sh
 
register: shell_output_collection
  with_items
: play_hosts
  delegate_to
: 127.0.0.1

Think it's a matter of using a filter and then a length filter after it but I can't quite crack it:

- name: count how many are 'a'
  set_fact
: count_of_a="{{ shell_output_collection.results | map(attribute='stdout') | ???match if value is 'a'??? | list | length }}"

The 'equalto' test is still in the jinja dev branch afaict and it's not even certain that that will help.

How else can this be accomplished?
Reply all
Reply to author
Forward
0 new messages