Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible Playbook error: Conflicting action statements with Hosts and Tasks

I am currently trying to play a couple of playbooks within another playbook. I use ansible version 2.9.6.

I made a playbook for this that calls out several roles. The reference works. But within the playbook I want to play, I get the following error: error conflicting action statements hosts tasks

I have multiple files as described above. For convenience, only two will be shown: the main.yml file for apache2 and my playbook to automate the tasks. I've shortened those to only show the conflict statements and added those right below.

serverdeploy code (shortened):

---
# webservers
- hosts: webservers
  become: yes
  
  roles:
    - apache2
...

main.yml code (shortened):

# task file for apache2
- hosts: webservers
  become: yes
  
  tasks:
  - name: Installing apache
...

Could anyone help me with this issue? I'd love to know what i'm doing wrong!

like image 986
Ravenium Avatar asked Sep 17 '25 17:09

Ravenium


1 Answers

Task files in roles can be done with no indentation at all:

E.G.: (BAD)

# 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
...

E.G.: (GOOD)

# 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
...
like image 68
malpanez Avatar answered Sep 19 '25 06:09

malpanez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!