$cat roles/test/tasks/main.yml
---
- name: "find war files on node"
shell: "find /var/www/Container*/ -name '*.war' -type f -print"
register: output
- name: "set facts"
set_fact:
wars: "{{ output.stdout_lines }}"
- name: print wars
command: echo "{{ item }}"
with_items: wars
which gives me:
TASK: [test | print wars] *****************************************************
changed: [127.0.0.1] => (item=/var/www/ContainerA/service2.war)
changed: [127.0.0.1] => (item=/var/www/ContainerA/service1.war)
changed: [127.0.0.1] => (item=/var/www/ContainerB/service2.war)
changed: [127.0.0.1] => (item=/var/www/ContainerB/service1.war)
I want to munge wars into an array of key/value pairs that look like this:
services:
- { container: 'ContainerA', service: 'service2' }
- { container: 'ContainerA', service: 'service1' }
- { container: 'ContainerB', service: 'service2' }
Any ideas on how I can accomplish this ? I am having a lot of trouble trying to map an array into another array of key value pairs.
I haven't been able to figure out substring matching either.
I can probably do this directly in the jinja template, but I'd like to just have a fact with the 'services' array.
Thanks.