Let assume following:
main-playbook.yml
- name: Play-1 hosts: localhost connection: local gather_facts: no roles: - role: my-role vars: newhost: 192.168.1.1 generated_playbook.yml
- name: Play-1 hosts: newhost gather_facts: yes tasks: - name: Task1 - name: Task2 - name: Task3 main task from the Role:
- name: "Role MAIN-1" add_host: name: newhost ansible_host: "{{newhost}}" - include: generated_playbook.yml Error:
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
Question:
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