How to import both playbooks and tasks in an Ansible playbook

2.3k views Asked by At

I have several playbooks that I sometimes execute individually but I also want to group them in one "master" playbook so that they can all be executed sequentially. I do this using ansible.builtin.import_playbook. In this same playbook I also want import a given task. However I am not able to write this in such a way that the ansible linter is happy.

I would expect that something like:

---
- name: Master Playbook
  hosts: all

- name: Playbook 1
  ansible.builtin.import_playbook: playbook1.yml

- name: Playbook 2
  ansible.builtin.import_playbook: playbook2.yml

- name: Task 1
  ansible.builtin.import_tasks: task1.yml

would work, however I get 'ansible.builtin.import_tasks' is not a valid attribute for a Play

If for the tasks I instead use:

  tasks:
    - name: Task 1
      ansible.builtin.import_tasks: .task1.yml

I get 'tasks' is not a valid attribute for a PlaybookInclude

If I set the tasks: line before - name: Playbook 1 I get instead

This task 'ansible.builtin.import_playbook' has extra params, which is only allowed in the following modules: ansible.windows.win_command, ansible.builtin.import_role, ansible.builtin.meta, include, ansible.builtin.command, ansible.builtin.group_by, ansible.builtin.win_shell, ansible.builtin.set_fact (...)

So how can I import both playbooks and tasks in the same playbook?

Unfortunately I haven't been able to find good documentation for this example, and the ones for the import_playbook and import_tasks aren't very clear. They also don't seem to be present in the Ansible lint documentation.

Thank you in advance

0

There are 0 answers