|
journal
all | Rob is 20,357 days old today. |
|
Entries this day: created-security-group-on-aws-with-ansible created security group on aws with ansible 09:35 Tuesday 05 July 2016 JSTThanks, Travis! For a long time I got an error: ERROR! 'ec2_group' is not a valid attribute for a PlayMy - name: Create security group
ec2_group:
name: "test_security_group"
description: "Test security group"
region: "ap-northeast-1"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 0.0.0.0/0
register: basic_firewall
On the verge of creating a question on SO, I figured out the problem. I had been using a portion of a role as a playbook. So to triage and get something working, my - hosts: localhost
connection: local
tasks:
- name: Create security group
ec2_group:
name: "test_security_group"
description: "Test security group"
region: "ap-northeast-1"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 0.0.0.0/0
register: basic_firewall
Can be run with The next step was to add a couple of variables: - hosts: localhost
connection: local
vars:
security_group_name: testing
aws_region: ap-northeast-1
project_name: "test"
my_ip: 1.2.3.4/32
tasks:
- name: Create security group
ec2_group:
name: "{{ project_name }}_security_group"
description: "{{ project_name }} security group"
region: "{{ aws_region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ my_ip }}"
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 0.0.0.0/0
register: basic_firewall
Next next step will be to put it into a role, which is where the top snippet should have been in the first place. permalink |