I'm pretty new to ansible and from reading things what I'm doing should work. I have the following file called aws.yml
---
- hosts: localhost
connection: local
gather_facts: no
vars:
aws_region: us-east-1
tasks:
- name: Main VPC
ec2_vpc:
state: present
cidr_block: 10.5.0.0/16
resource_tags: {"environment": "prod"}
region: "{{ aws_region }}"
dns_hostnames: no
dns_support: yes
instance_tenancy: default
internet_gateway: yes
subnets:
- cidr: 10.5.151.96/27
az: "{{ aws_region }}a"
resource_tags: {"Name": "private"}
- cidr: 10.5.151.128/27
az: "{{ aws_region }}b"
resource_tags: {"Name": "private"}
- cidr: 10.5.151.160/27
az: "{{ aws_region }}c"
resource_tags: {"Name": "private"}
When I run ansible-playbook over it I get the following
$ ansible-playbook aws.yml
ERROR: Unable to find an inventory file, specify one with -i ?
From my understanding is the hosts: localhost is supposed to take the place of using -i and since I'm trying to create a VPC here I don't want to ssh into machines to build it.
Thanks
You need to point to an inventory file (even an empty one), because the playbook only says which hosts the play applies to, but does not provide the means to define such list, the inventory does. Luckily,
localhost
is available by default: