无法解决ansible playbook中的语法错误

时间:2017-10-13 14:00:27

标签: ansible ansible-2.x

我一直在尝试部署我的剧本,但不确定错误是什么。我的剧本看起来像这样:

- name: trying to find sb ami
   ec2_ami_find:
      owner: self
      name: SB
   register: ami_find

 - name : use custom ami
   ec2:
     image: "{{ ami_find.results[0].ami_id }}"
     instance_type: t2.small
     key_name: mykey
     region: us-east-1
     wait: yes
     register: ec2

我不断得到错误:

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/root/git-work/ansible/sparkbeyond.yml': line 16, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

   register: ami_find

  ^ here
There appears to be a tab character at the start of the line.

YAML does not use tabs for formatting. Tabs should be replaced with spaces.

For example:
    - name: update tooling
      vars:
        version: 1.2.3
#    ^--- there is a tab there.

Should be written as:
    - name: update tooling
      vars:
        version: 1.2.3
# ^--- all spaces here.

有人可以帮助我,为什么我会收到这样的错误。我在ubuntu机器上使用ansible 2.3版

1 个答案:

答案 0 :(得分:1)

你的缩进在第一场比赛中没有了。在第二次播放中,register不是ec2模块的参数。

- name: trying to find sb ami
  ec2_ami_find:
    owner: self
    name: SB
  register: ami_find

- name: use custom ami
  ec2:
    image: "{{ ami_find.results[0].ami_id }}"
    instance_type: t2.small
    key_name: mykey
    region: us-east-1
    wait: yes
  register: ec2