Skip to content

Instantly share code, notes, and snippets.

@carlessanagustin
Last active October 11, 2018 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carlessanagustin/6b8032e900aeb430cb092fad8e1871d5 to your computer and use it in GitHub Desktop.
Save carlessanagustin/6b8032e900aeb430cb092fad8e1871d5 to your computer and use it in GitHub Desktop.
ANSIBLE: Change AWS EC2 Security Group configuration.
#!/usr/local/bin/ansible-playbook -v
---
- hosts: localhost
gather_facts: False
connection: local
vars:
rule_list:
- { proto: tcp, from_port: 80, to_port: up, cidr_ip: 10.0.0.1/32 }
- { proto: tcp, from_port: 443, to_port: 443, cidr_ip: 10.0.0.1/32 }
ec2_group_region: eu-west-1
ec2_group_vpc: 'vpc-XXXXXXX'
ec2_group_description: 'This is a description'
ec2_group_name: security_group_name
vars_files:
- vars/aws_config.yml
tasks:
- name: Change security group
ec2_group:
name: '{{ ec2_group_name }}'
description: '{{ ec2_group_description }}'
vpc_id: '{{ ec2_group_vpc }}'
aws_access_key: '{{ access_key }}'
aws_secret_key: '{{ secret_key }}'
region: '{{ ec2_group_region }}'
rules: '{{ rule_list }}'
@njmiller31
Copy link

Thanks for posting this. Am I correct in assuming that the key to this working is setting the gather_facts to false? I'm trying to update the cidr_ip of one of my SG rules, but I keep getting the error: " The specified rule does not exist in this security group"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment