LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

How do you pass variables to a playbook you bring in with import_playbook?

Add vars: to the import_playbook entry. The plays in the imported playbook can then use those variables.

- name: Import play file and set the variable
  ansible.builtin.import_playbook: play.yml
  vars:
    package: mariadb

This works the same way as passing variables to a task file: the imported playbook is written generically (for example name: "{{ package }}" in its tasks), and the main playbook decides the concrete value.

Since the import is static, the values have to be known while the playbook is parsed. Values from vars: or --extra-vars are fine. The same playbook can be imported several times with different vars: to run it for several packages.

Go deeper:

From Quiz: ITIA / Ansible: Complex Playbooks with Imports and Includes | Updated: Nov 26, 2026