Ansible Playbook 错误:操作语句与主机和任务冲突

Rav*_*ium 4 automation ansible

我目前正在尝试在另一本剧本中播放几本剧本。我使用ansible版本2.9.6。

我为此制作了一本剧本,其中列出了几个角色。参考作品。但在我想玩的剧本中,出现以下错误: error conflicting action statements hosts tasks

我有多个文件,如上所述。为了方便起见,仅显示两个:apache2 的 main.yml 文件和我用于自动化任务的剧本。我已经缩短了这些内容,只显示冲突陈述,并在下面添加了这些内容。

服务器部署代码(缩短):

---
# webservers
- hosts: webservers
  become: yes
  
  roles:
    - apache2
...
Run Code Online (Sandbox Code Playgroud)

main.yml 代码(缩短):

# task file for apache2
- hosts: webservers
  become: yes
  
  tasks:
  - name: Installing apache
...
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题吗?我很想知道我做错了什么!

小智 5

角色中的任务文件可以完全不缩进地完成:

EG:(不好)

# This is Playbook (style) which is not right for task file.
# task file for apache2
- hosts: webservers
  become: yes
  
  tasks:
  - name: Installing apache
      apt:
        name: apache2
        state: latest
...
Run Code Online (Sandbox Code Playgroud)

例如:(好)

# This is task file (style) which is how it should be.
# You can ident or leave like this and import/include_file
# task file for apache2
- name: Installing apache
  apt:
    name: apache2
    state: latest
...
Run Code Online (Sandbox Code Playgroud)