播放 ansible playbook 时出错

播放 ansible playbook 时出错

我刚刚在 aws 的服务器上安装了 ansible,然后创建了一个剧本来运行它,但在运行时出现如下错误:

ERROR! 'copy' is not a valid attribute for a Play

The error appears to have been in '/root/amritha/pega-cloud-infrastructure/ansible/roles/datadog-pegalogs-apptier/tasks/main.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

有问题的一行似乎是:

- name: copy the pattern_search.txt file which has patterns to be grepped
  ^ here

我的剧本如下:


- name: copy the pattern_search.txt file which has patterns to be grepped
  copy: src=pattern_search.txt dest=/root/pattern_search.txt owner=root group=root mode=755

- name: copy the logsearchtest.sh script which greps patterns and prints pattern.txt file
  copy: src=logsearchtest.sh dest=/root/logsearchtest.sh owner=root group=root mode=755
  script: /root/logsearchtest.sh

- name: schedule cron to run every 5 minutes
  #cron: */5 * * * * root /root/logsearchtest.sh -c "script to grep patterns;"
  cron: name="logsearch script for grepping pega alert logs" minute="5" job="/root/logsearchtest.sh > /dev/null"

- name: copy parsers.py fucntion to datadog lib path
  copy: src=parsers.py dest=/opt/datadog-agent/agent/checks/libs/parsers.py owner=root group=root mode=755

- name: copy datadog agent configuration file
  copy: src=datadog-agent.conf dest=/etc/datadog.conf owner=root group=root mode=755

另请注意,我有一个目录,里面有一个文件filestasks。该files文件夹包含所有提到的文件,tasks文件夹包含上述剧本。

答案1

我假设您正在运行 ansible-playbook /blah/tasks/whatever.yml?

如果是这样,那就是你的问题。剧本的正确结构是:

---
name: my playbook
  roles:
    - Arole
    - Brole
# other playbok attributes
  tasks:
    - name: copy stuff
      copy: src=foo dest=bar
    - name: include cool tasks
      include: ../tasks/snafu.yml
      when: poobar == "fubar"

相关内容