【问题标题】:Getting error in the first line of YAML file在 YAML 文件的第一行出现错误
【发布时间】:2017-06-20 21:26:42
【问题描述】:

这是我要运行以创建 ec2 实例的 yml 脚本。但是无论我在第一行放什么,我都会在第一行出错。

语法检查并且没问题。

错误:

"ERROR! A malformed block was encountered.

The error appears to have been in '/root/aws-create/ec2c.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

-
  name: Stage instance(s)
  ^ here"

-
  name: Stage instance(s)
  hosts: aws
  connection: ssh
  remote_user: ec2-user
  become: yes
  gather_facts: false
  vars:
    keypair: newrhel_2
    instance_type: t2.micro
    security_group: default
    image: ami-b55a51cc
    aws_region: us-west-2
    aws_access_key: xxxxxxxxxxxxxxxxxxxxxxxx
    aws_secret_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  tasks:
    ec2:
      aws_access_key={{aws_access_key}}
      aws_secret_key={{aws_secret_key}}
      keypair={{keypair}}
      group={{security_group}}
      instance_type={{instance_type}}
      image={{image}}
      region={{aws_region}}
      wait=true
      count=1

【问题讨论】:

  • 第一行的- 是干什么用的?我见过三个 --- 表示一个 YAML 文件,但不是一个单独的。
  • @Jack 表示一个列表元素——YAML 中最基本的结构之一。剧本是剧本的清单。
  • 好的——我以前从来没有单独见过一个。我会把name: 放在同一行。

标签: amazon-web-services amazon-ec2 ansible yaml


【解决方案1】:

tasks 应该包含一个列表,而不是一个字典(并且因为您使用 Ansible 表示法,ec2 作为 YAML 字典无效)。需要在ec2前加一个连字符:

tasks:
  - ec2:

【讨论】:

  • 非常感谢。我是yaml的新手。你拯救了我的一天。
猜你喜欢
  • 2021-11-15
  • 1970-01-01
  • 2022-06-12
  • 2020-02-20
  • 1970-01-01
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多