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.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/dbb96514-81e1-46be-b057-3771db75eb0b%40googlegroups.com.

Reply via email to