help with munging a variable

17 views
Skip to first unread message

abel.makko...@gmail.com

unread,
Dec 15, 2015, 1:18:40 PM12/15/15
to Ansible Project
I can create an array wars like so ( I *THINK* it's an array, pretty sure it's an array )

$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: '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.



Reply all
Reply to author
Forward
0 new messages