0
votes

my playbook directory structure.

/ansible_repo/
└── playbooks/
    ├──playbooks1.yml
    ├──playbooks2.yml
├── somerole.yml  --> main playbook with roles
└── roles/
    └── somerole
        ├── default
        │   └── main.yml
        ├── handler
        │   └── main.yml
        ├── tasks
        │   └── main.yml
        └── vars
            └── main.yml

playbooks1.yml :

---
- hosts: all
  tasks:
    - pause:
        minutes: 3
    - name: ping host
      win_ping:

somerole.yml :

---
- hosts: ci_host
  roles:
    - somerole

somerole\tasks\main.yml :

---
- include: playbooks/playbooks1.yml

when I run the role on some host:

ansible-playbook role-test.yml -vv --limit somehost

I get this error:

fatal: [somehost]: FAILED! =>
  reason: |-
    conflicting action statements: hosts, tasks

if I change the like that it passed:

- pause:
  minutes: 3
- name: ping host
  win_ping:

I tried understand how to set hosts and tasks in both, role-tasks-main and playbook.yml and include the playbook into the role task.

if I get conflict I can config hierarchy host?

1
why are you using host configuration in a yml not in a host.ini ? Also dos your ping check work ?user3732793
I have also host inventory, I show here example to my repoIdo Harel
so what does ansible all -m ping says ?user3732793
the playbook run on all hosts in inventory and run one by one win_ping model(its example playbook, it can be linux model, shell model or something else), I want run role, with many tasks in tasks dir, and run in main all tasks and add one more playbook from playbooks dirIdo Harel
difficult to understand what exactly you want. Usually you create one playbook and test it until works with your one throwaway host. That way it's diffcult to isolate the problem. Sorry I can't help hereuser3732793

1 Answers

0
votes

The error indicates that you are including a playbook inside a role, and for a role hosts and tasks are not allowed.

As somerole.yml is your main playbook, you can invoke other playbooks and roles as necessary.

Example:

- name: run playbook playbook1
  import_playbook: playbooks/playbooks1.yml

- hosts: ci_host
  roles:
    - somerole

- name: run playbook playbook2
  import_playbook: playbooks/playbooks2.yml