Let assume following:


- name: Play-1
  hosts: localhost
  connection: local
  gather_facts: no
    - role: my-role


- name: Play-1
  hosts: newhost
  gather_facts: yes
  - name: Task1
  - name: Task2
  - name: Task3

main task from the Role:

- name: "Role MAIN-1"
    name: newhost
    ansible_host: "{{newhost}}"

- include: generated_playbook.yml


ERROR! conflicting action statements: hosts, tasks

The error appears to be in 'generated_playbook.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Generated Playbook
  ^ here

I create new role and include this role in the main playbook.
In this role I add new host to in-memory inventory and than, I generate new playbook with j2 template example output generated_playbook.yml

Is there a way to run this new generated playbook only on the new added host but not adding anything else to main playbook?
I was trying to use import-playbook or include inside the role but this fails


1 Answer 1


It's not possible. Quoting from ansible.builtin.import_playbook

Files with a list of plays can only be included at the top level.

The example explicitly shows this

- name: This DOES NOT WORK
  hosts: all
    - debug:
        msg: task1

    - name: This fails because I'm inside a play already
      import_playbook: stuff.yaml


  • There is no include_playbook. See what include_* and import_* modules are available.
shell> ansible-doc -t module -l | grep include_

include_role    Load and ...  
include_tasks   Dynamically inclu...
include_vars    Load variables from files, dynamically...
shell> ansible-doc -t module -l | grep import_

import_playbook Imp...        
import_role     Import a ro...
import_tasks    Impo...
  • Quoting note from import_module:

This is a core feature of Ansible, rather than a module, and cannot be overridden like a module.

You must log in to answer this question.

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