一个尝试使用 ansible 的 newbee 和一个奇怪的错误

a newbee trying to use ansible and a weird error

我有这个剧本:

- name: main playbook
  hosts: 127.0.0.1
  connection: local
  sudo: Yes
  gather_facts: True
  vars_files:
- /home/core/REPO/alonso/core2door-integration/workflows/core2door.ansible/vars-feed.yml
  tasks:
- include: tasks/feed-adapter.yml

tasks/feed-adapter.yml

# This playbook deploys feed-adapter application in this host. This app needs a jar that basically writes to HDFS and write a log in a system,
# actually Impala. Variables are described within vars-feed.yml file.
- name: feed-adapter playbook
  hosts: "{{host_feed}}"
  remote_user: "{{remote-user}}"
  sudo: Yes

- name: Creates feed_adapter_outputpath directory
  file: path=/var/app/feed-adapter/ state=directory

- name: Creates check-feed-adapter-folders_outputpath directory
  file: path=/var/app/check-feed-adapter-folders/ state=directory

- name: Copy supervisor conf files to /etc/supervisor.d folder
  copy: src=/home/core/REPO/alonso/core2door-integration/feed-adapter/feed_adapter_Sip_Pub.conf dest=/etc/supervisor.d/feed_adapter_Sip_Pub.conf owner=root group=root mode=0644

- name: Copy generated jar to destination folder
  copy: src=/home/core/REPO/alonso/core2door-integration/feed-adapter/target/feed-adapter-0.0.1-SNAPSHOT.jar dest=/var/app/check-feed-adapter-folders/feed-adapter.jar mode=0644

- name: Copy necessary .properties files to destination folder
  copy: src=/home/core/REPO/alonso/core2door-integration/feed-adapter/feed-adapter-SIP-Pub.properties dest=/var/app/check-feed-adapter-folders/feed-adapter-SIP-Pub.properties mode=0644

- name: Copy check-feed-adapter-folders jar to destination folder
  copy: src=/home/core/REPO/alonso/core2door-integration/CheckFeedAdapterFolders/target/CheckFeedAdapterFolders-0.0.1-SNAPSHOT.jar dest=/var/app/check-feed-adapter-folders/CheckFeedAdapterFolders.jar mode=0644

- name: Copy check.sh script to destination folder
  copy: src=/home/core/REPO/alonso/core2door-integration/CheckFeedAdapterFolders/check.sh dest=/var/app/check-feed-adapter-folders/check.sh mode=0644

当我尝试 运行 剧本时,它 returns 我这个输出:

$ ansible-playbook playbook.yml --syntax-check --i hosts.txt
/usr/lib/python2.6/site-packages/setuptools-12.0.5-py2.6.egg/pkg_resources/__init__.py:1222: UserWarning:
/home/core/.python-eggs is writable by group/others and vulnerable to
attack when used with get_resource_filename. Consider a more secure
location (set with .set_extraction_path or the PYTHON_EGG_CACHE
environment variable).

playbook: playbook.yml

ERROR: copy is not a legal parameter at this level in an Ansible Playbook

请帮忙,我是ansible的新手。

更新

在 Daniel 的建议下,我仔细地缩进了剧本,但我收到了这个错误:

$ vi tasks/feed-adapter.yml
$ ansible-playbook playbook.yml --syntax-check --i hosts.txt
/usr/lib/python2.6/site-packages/setuptools-12.0.5-py2.6.egg/pkg_resources/__init__.py:1222: UserWarning:
/home/core/.python-eggs is writable by group/others and vulnerable to
attack when used with get_resource_filename. Consider a more secure
location (set with .set_extraction_path or the PYTHON_EGG_CACHE
environment variable).

playbook: playbook.yml

ERROR: file is not a legal parameter at this level in an Ansible Playbook

更新 2:

使用 -vvvv 执行 ansible-playbook 显示相同的输出:

ERROR: file is not a legal parameter at this level in an Ansible Playbook
[core@dub-vcd-vms171 core2door.ansible]$ ansible-playbook --i hosts.txt -vvvv playbook.yml
/usr/lib/python2.6/site-packages/setuptools-12.0.5-py2.6.egg/pkg_resources/__init__.py:1222: UserWarning: /home/core/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
ERROR: file is not a legal parameter at this level in an Ansible Playbook

我猜错误来自这一行:

- name: Creates feed_adapter_outputpath directory
  file: path=/var/app/feed-adapter/ state=directory

在使用 yaml 文件时,您必须非常小心行缩进。这里的错误大概是第28行的copy元素引起的:

  - name: ...
  copy: ...

copy前面加两个空格,看起来像这样:

  - name: ...
    copy: ...