ansible.builtin.include_role (v2.5.6) — module

Load and execute a role

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

Authors: Ansible Core Team (@ansible)

preview | supported by core

Install Ansible via pip

Install with pip install ansible==2.5.6

Description

Loads and executes a role as a task dynamically. This frees roles from the `roles:` directive and allows them to be treated more as tasks.

Unlike M(import_role), most keywords, including loops and conditionals, apply to this statement.

This module is also supported for Windows targets.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- include_role:
    name: myrole
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run tasks/other.yaml instead of 'main'
  include_role:
    name: myrole
    tasks_from: other
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Pass variables to role
  include_role:
    name: myrole
  vars:
    rolevar1: value from task
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Use role in loop
  include_role:
    name: myrole
  with_items:
    - '{{ roleinput1 }}'
    - '{{ roleinput2 }}'
  loop_control:
    loop_var: roleinputvar
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Conditional role
  include_role:
    name: myrole
  when: not idontwanttorun

Inputs

    
name:
    description:
    - The name of the role to be executed.
    required: true

private:
    default: None
    description:
    - If C(True) the variables from C(defaults/) and C(vars/) in a role will not be made
      available to the rest of the play.

vars_from:
    default: main
    description:
    - File to load from a role's C(vars/) directory.
    required: false

tasks_from:
    default: main
    description:
    - File to load from a role's C(tasks/) directory.
    required: false

defaults_from:
    default: main
    description:
    - File to load from a role's C(defaults/) directory.
    required: false

allow_duplicates:
    default: true
    description:
    - Overrides the role's metadata setting to allow using a role more than once with
      the same parameters.
    required: false