# merging aws security rules

**URL:** <https://forum.ansible.com/t/merging-aws-security-rules/24224>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [April 16, 2017, 10:50pm UTC](https://forum.ansible.com/t/merging-aws-security-rules/24224 "2017-04-16T22:50:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Graham](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@Matt\_Graham](https://forum.ansible.com/u/Matt_Graham)\
**Post date:** [April 16, 2017, 10:50pm UTC](https://forum.ansible.com/t/merging-aws-security-rules/24224/1 "2017-04-16T22:50:43Z")

</div>

I think someone once may have posted something like this but Im trying to merge a list of base firewall rules (AWS) into a master\_rules for that role

Example: all the roles listed in default/main.yml would merge in the base ip rules. I cant use python eval and not sure what is the best way to tackle merging. Here’s what Ive been attempting. Im sure there is an easier way Im missing. Thanks for any help.

defaults/main.yml

roles:

- nat
- apps
- db
- web
- log

vars/  
base.yml  
apps.yml  
rules:

- proto: tcp  
from\_port: 22  
to\_port: 22  
cidr\_ip: 0.0.0.0/0

- name: Include ip Base rules  
include\_vars:  
file: “base.yml”  
name: base

- name: Include Rules per Role  
include\_vars:  
file: “{{ item }}.yml”  
name: “{{ item }}\_rules”  
with\_items:

- “{{ roles }}”

- name: Set facts  
set\_fact:  
master\_rules\_for\_{{ item }}: “{{ (item + ‘\_rules’)[‘rules’] | union(base[‘rules’]) }}”  
with\_items:

- “{{ roles }}”
