# is it possible to add multiple security group rules to a security group using os\_security\_group & os\_security\_group\_rule?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-add-multiple-security-group-rules-to-a-security-group-using-os-security-group-os-security-group-rule/22862>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [October 23, 2016, 8:17am UTC](https://forum.ansible.com/t/is-it-possible-to-add-multiple-security-group-rules-to-a-security-group-using-os-security-group-os-security-group-rule/22862 "2016-10-23T08:17:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glyn\_Davies](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@Glyn\_Davies](https://forum.ansible.com/u/Glyn_Davies)\
**Post date:** [October 23, 2016, 8:17am UTC](https://forum.ansible.com/t/is-it-possible-to-add-multiple-security-group-rules-to-a-security-group-using-os-security-group-os-security-group-rule/22862/1 "2016-10-23T08:17:58Z")

</div>

Hi Folks,

I am wondering if it is possible to add multiple rules to an openstack security group using a loop mechanism such as with\_items or with\_dict?

I gave found examples of where this is possible in AWS using somthing like

security\_groups:

- name: http\_access  
rules:
- proto: tcp  
from\_port: 80  
to\_port: 80  
cidr\_ip: 0.0.0.0/0
- proto: tcp  
from\_port: 22  
to\_port: 22  
cidr\_ip: 0.0.0.0/0  
rules\_egress: 

tasks:

- name: add security groups.  
ec2\_group:  
name: “{{ item.name }}”  
description: add security group rules  
region: “{{ item.region }}”  
state: present  
rules: “{{ item.rules }}”  
rules\_egress: “{{ item.rules\_egress }}”  
with\_items: security\_groups

I have tried various configurations to try and achieve the same outcome using os\_security\_group and os\_security\_group\_rule but cannot manage to get more than a single rule attached to any one security group.

Thanks in advance for your time.

Cheers,  
Glyn
