After some fighting I found the way to capture the vpc id by registering
the output. What I was missing all along in the variable string was the
[0].
- name: get vpc_id
ec2_vpc_net_facts:
region: "{{ region }}"
filters:
"tag:Name": Svpc
register: vpcdata
- debug:
var=vpcdata.vpcs[0].id
- name: Create VPC Security Groups
ec2_group:
state: present
name: "{{ env }}sshIn"
description: allow ssh in from any
region: "{{ region }}"
vpc_id: "{{ vpcdata.vpcs[0].id }}"
rules:
- proto: tcp
cidr_ip: x.x.x.x/x
from_port: 22
to_port: 22
Thanks
On Tuesday, 19 April 2016 11:12:34 UTC-4, lunser wrote:
>
> 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"}
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1dbd5ac7-04f2-41bf-bee4-ab3d239f7d60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.