Skip to content

Instantly share code, notes, and snippets.

@filipenf
Created January 20, 2016 12:48
Show Gist options
  • Save filipenf/4869cf597c264031f529 to your computer and use it in GitHub Desktop.
Save filipenf/4869cf597c264031f529 to your computer and use it in GitHub Desktop.
Ansible with_nested example
---
- hosts: localhost
connection: local
vars:
all_networks:
- 10.80.128.0/20
- 10.80.144.0/20
- 10.80.208.0/20
- 10.10.5.0/24
- 10.10.4.0/24
- 10.16.5.0/24
- 10.30.1.0/24
- 10.191.64.0/19
- 10.40.1.0/24
- 10.50.32.0/19
- 10.50.96.0/19
- 10.50.160.0/19
- 10.20.32.0/19
- 10.20.96.0/19
- 10.20.160.0/19
- 10.42.250.0/24
- 10.42.240.0/24
my_rules:
- proto: all
from_port: -1
to_port: -1
tasks:
- set_fact:
args:
rule:
proto: "{{ item.1.proto }}"
from_port: "{{ item.1.from_port }}"
to_port: "{{ item.1.to_port }}"
cidr_ip: "{{ item.0 }}"
with_nested:
- "{{ all_networks }}"
- "{{ my_rules }}"
register: all_rules
- set_fact: all_rules="{{all_rules.results | map(attribute='ansible_facts.rule') | list }}"
- debug: var=all_rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment