AWS module woes in Ansible

Hi Ansible peeps,

Trying to get an AWS modules working in an Ansible playbook. Specifically I want to create a VPC using an Ansible playbook, but no matter what I do, always get the error:

ERROR! ‘ec2_vpc_net’ is not a valid attribute for a Play (for VPC obviously)

Doesn’t seem to matter which aws module I try to use, always gives similar error. For example, ec2:

ERROR! ‘ec2’ is not a valid attribute for a Play (for VPC obviously)

Have created several playbooks using the manual examples, as well as other online examples.

http://docs.ansible.com/ansible/ec2_vpc_net_module.html#support

http://jeremievallee.com/2016/07/27/aws-vpc-ansible/

I’ve copied these playbooks verbatim, checked the yaml format thru a linter, etc. Doesn’t matter always get the same error using ansible-playbook, i.e.

ansible-playbook -i localhost, vpc-template.yml

ERROR! ‘ec2_vpc_net’ is not a valid attribute for a Play

The error appears to have been in ‘/home/ubuntu/ansible/playbooks/networking/vpc-template.yml’: line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • ec2_vpc_net:
    ^ here

If I run the module manually, it works fine:

ansible local -m ec2_vpc_net -a “name=test.vpc cidr_block=10.153.0.0/22 region=us-west-2”

I’m pretty sure that error message is a false flag and I’m missing something really simple, but I’ve been unable to track it down. Any help or pointers appreciated.

I’m running Ansible 2.3.0.0
Ubuntu 16.04
python 2.7.12
boto 2.48.0

Can you show us your playbook.

I found another user having the same problem. Not sure if it was having the hosts: or tasks: defined (or both?) but it works now with this

Working playbook:

  • hosts: localhost
    connection: local
    tasks:
  • name: Create vpc
    ec2_vpc_net:
    name: “Test.VPC”
    state: present
    cidr_block: 10.151.0.0/22
    region: us-west-2

Original playbook:

  • ec2_vpc_net:
    name: “Test.VPC”
    state: present
    cidr_block: 10.151.0.0/22
    region: us-west-2

Yes, having hosts: and tasks: is requires to make it a valid playbook. Your original one is valid YAML, but not a valid playbook.