ansible.builtin.import_tasks (v2.16.5) — module

Import a task list

| "added in version" 2.4 of ansible.builtin"

Authors: Ansible Core Team (@ansible)

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
file:
    description:
    - Specifies the name of the file that lists tasks to add to the current playbook.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

free-form:
    description:
    - '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.

See also