I have an Ansible script to create EC2 security group. It looks like this:
- name: Create HTTP Security Group
local_action:
module: ec2_group
region: "{{ region }}"
vpc_id: "{{ vpc }}"
name: sg_http
description: Security group for HTTP access
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
register: sg_http
However this created a security group with inbound http access but also full outbound access. I would like to write a task which deletes the egress rule automatically added by AWS allowing all outgoing traffic but not the whole security group. I tried using the state as present, but it doesn't seem to work as expected:
- name: Delete HTTP Rule
local_action:
module: ec2_group
region: "{{ region }}"
vpc_id: "{{ vpc }}"
name: sg_http
description: Security group for HTTP access
egress_rules:
- proto: all
from_port: 0
to_port: 65535
cidr_ip: 0.0.0.0/0
state: absent
register: sg_http
What would be the better way to do this?