I'd like to know how to conditionally import a playbook.
I have a master playbook which calls several others
The master looks like this:
---
- name: Query user for information
import_playbook: query_user.yaml
- name: Car required
import_playbook: determine_car_information.yaml
when: car_required == True
query_user.yaml looks like this
---
- hosts: 127.0.0.1
connection: local
vars_prompt:
- name: car_required
prompt: 'Is a car required (y / n)?'
private: no
tasks:
- name: Register variable from above prompt
set_fact:
car_required: "{{ car_required }}"
No matter what, the
determine_car_information playbook is always run, regardless of what
car_required is set to.
I've also tried wrapping this in a tasks / block section as per the following:
---
- name: Query user for information
import_playbook: query_user.yaml
- tasks:
- name: Gather car info if car is required
block:
- name: Car required, query for info
import_playbook: determine_car_information.yaml
when: car_required|lower == "y"
This results in the following:
ERROR! this task 'import_playbook' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars,
include_tasks, include_role, import_tasks, import_role, add_host, group_by, set_fact, raw, meta
I'd really like to understand why this is occurring / if there's an alternate solution.