I am a complete n00b to Ansible (or any scripting language for that matter) and would appreciate some help with my syntax/indentation (?) problem.
This is my simple playbook, the goal is to create an instance in AWS and add it to a security group.
I am quite confused as to what the problem is as I am getting 2 different errors from different yaml checkers:
1) Yamllint tells me: "(): did not find expected key while parsing a block mapping at line 2 column 3 "
2) Swagger tells me: "YAML Syntax Error. Bad indentation of a sequence entry at line 6, column 3: - name: Create a security group ^" (Points to the second "- name")
Any help would be great~
Cheers~
---
- name: Provision an EC2 Instance and assign an SG
hosts: local
connection: local
gather_facts: False
- name: Create a security group
local_action:
module: ec2_group
name: test_sg
region: us-west-2
rules:
- proto: tcp
type: ssh
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
rules_egress:
- proto: all
type: all
cidr_ip: 0.0.0.0/0
- name: Create new instance
local_action: ec2
group= test_sg
instance_type= t1.micro
image= ami-9ff7e8af
wait= true
region= us-west-2
keypair= XXX-keypair
count= 1
register: ec2
In line 6 you're introducing a new item of a list (the dash symbol). But the yaml parser doesn't know what to do with the item. There are two approaches.
Swagger considers it is part of the main list and it is at the same level as line 2. So it complains about bad indentation in line 6.
Yamllint understand it's a sublist but it doesn't know what key to assign the sublist.
Most likely, yamllint is correct, and you've missed a key called tasks
. Even with that bit fixed, you'll find there are other identations problems. Below I've pasted what I understand is the correct text (from a Yaml perspective)
---
- name: Provision an EC2 Instance and assign an SG
hosts: local
connection: local
gather_facts: False
tasks:
- name: Create a security group
local_action:
module: ec2_group
name: test_sg
region: us-west-2
rules:
- proto: tcp
type: ssh
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
rules_egress:
- proto: all
type: all
cidr_ip: 0.0.0.0/0
- name: Create new instance
local_action: ec2
group= test_sg
instance_type= t1.micro
image= ami-9ff7e8af
wait= true
region= us-west-2
keypair= XXX-keypair
count= 1
register: ec2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.