Hi,
I am getting facts from the ec2_vpc_net_facts module which I’m trying to grab the vpc-id from the output and use it as a variable to create a security group. This seems that it should be easy enough and I’ve read that ansible creates variables automatically but the example that I found doesn’t not seem to work here. I thought I’d post here to see if someone else has done this sort of thing.
Thanks so much,
Ladean
---- main.yml
-
name: get vpc_id
ec2_vpc_net_facts:
region: “{{ region }}”
filters:
“tag:Name”: Svpc -
debug:
var=ansible_ec2_vpc_vpc_id -
name: Create VPC Security Groups
ec2_group:
state: present
name: “{{ env }}sshIn”
description: allow ssh in from any
region: “{{ region }}”
vpc_id: “{{ ansible_ec2_vpc_vpc_id }}”
rules: -
proto: tcp
cidr_ip: x.x.x.x/x
to_port: 22
---- results
TASK [awsvpc : get vpc_id] *****************************************************
ok: [localhost]
TASK [awsvpc : debug] **********************************************************
ok: [localhost] => {
“ansible_ec2_vpc.vpcs_id”: “VARIABLE IS NOT DEFINED!”
}
TASK [awsvpc : Create VPC Security Groups] *************************************
fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “‘ansible_ec2_vpc_vpc_id’ is undefined”}