Skip to content

import_tasks

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 2.4.

Synopsis

  • Imports a list of tasks to be added to the current playbook for subsequent execution.

Parameters

Parameter Defaults / Choices Comments
file
str
Specifies the name of the file that lists tasks to add to the current playbook.
Version Added: 2.7
free-form Specifies the name of the imported file directly without any other option C(- import_tasks: file.yml).
Most keywords, including loops and conditionals, only apply to the imported tasks, not to this statement itself.
If you need any of those to apply, use M(ansible.builtin.include_tasks) instead.

Notes

Note

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

Examples

- hosts: all
  tasks:
    - ansible.builtin.debug:
        msg: task1

    - name: Include task list in play
      ansible.builtin.import_tasks:
        file: stuff.yaml

    - ansible.builtin.debug:
        msg: task10

- hosts: all
  tasks:
    - ansible.builtin.debug:
        msg: task1

    - name: Apply conditional to all imported tasks
      ansible.builtin.import_tasks: stuff.yaml
      when: hostvar is defined

Authors

  • Ansible Core Team (@ansible)