0

I'm trying to use Ansible to create a playbook that includes a different playbooks as one of its' tasks.

To clarify, the playbook is meant to deploy Linux servers, and one of the steps is to clone a git repository.

When importing it (I tried using import_tasks, include_tasks, import_playbook, and include_playbook), Ansible returns the following error:

ERROR! conflicting action statements: hosts, gather_facts

Sure enough, when I edit the git playbook and remote the hosts statement, the import works without issue.

However, the git cloning is also meant to run independently (to keep said repository in sync), and therefore must include the hosts directive as well.

What I'm essentially looking for is a way to import a playbook's tasks, with the importing playbook's hosts instead of the imported playbook's hosts.

I can simply remove the hosts directive from the git playbook and call it via some other playbook, but I'm wondering if there's a simpler way, or perhaps I'm just missing the right syntax.

Is there a simple way to import a playbook's tasks without its' hosts?

Thanks!

1 Answer 1

0

hosts: and gather_facts: can only exist in the top-most level of a play.

You should either

  1. Write your playbook as a role which connects to the target server
  2. Remove the conflicting statements and use delegate_to: when including your playbook tasks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .