---
- hosts: localhost
gather_facts: no
vars:
instances:
- id: 1234
type: web
- id: 1456
type: web
- id: 1678
type: web
- id: 3456
type: proxy
- id: 2567
type: proxy
- id: 2566
type: db
- id: 4900
type: db
tasks:
- name: Set Fact for proxy
set_fact:
new_proxy: "{{ new_proxy|default([]) + [ { 'id': item.id } ] }}"
loop: "{{ instances }}"
when: item.type == 'proxy'
- name: set Fact for db
set_fact:
new_db: "{{ new_proxy|default([]) + [ {'id': item.id } ] }}"
loop: "{{ instances }}"
when: item.type == 'db'
- name: set Fact for web
set_fact:
new_web: "{{ new_proxy|default([]) + [ {'id': item.id } ] }}"
loop: "{{ instances }}"
when: item.type == 'web'
- name: Print facts
debug:
msg: "Web - {{ new_web }} - DB - {{ new_db }} - Proxy - {{ new_proxy }}"
- name: Final set fact
set_fact:
new_instances: "{{ new_instances|default([]) + [ {'db': new_db}, {'web': new_web}, {'proxy': new_proxy} ] }}"
- name: Print final fact
debug:
var: new_instances
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20191122201219.5d637e3c%40gmail.com.