# Ignore imported playbooks completely when defined

**URL:** <https://forum.ansible.com/t/ignore-imported-playbooks-completely-when-defined/32574>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [March 31, 2020, 7:00pm UTC](https://forum.ansible.com/t/ignore-imported-playbooks-completely-when-defined/32574 "2020-03-31T19:00:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronen\_Levinson](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Ronen\_Levinson](https://forum.ansible.com/u/Ronen_Levinson)\
**Post date:** [March 31, 2020, 7:00pm UTC](https://forum.ansible.com/t/ignore-imported-playbooks-completely-when-defined/32574/1 "2020-03-31T19:00:03Z")

</div>

Hi,

I’m using ansible version 2.7.17 and combining multiple playbooks in one file.  
One of my playbooks I’m running conditionally with when and a condition.  
My problem is when my condition is false, I want ansible to completely ignore my playbook and not load anything related to this playbook.  
I tried using both import\_playbook and include, which seems to have similar results.  
The call to the playbook looks like that:

- name: Include kubespray tasks  
include: …/kubespray/cluster.yml  
when: cluster\_installation

in my output you can see ansible run the handlers inside the ignored playbook (keeping for 2 more minutes):

PLAYBOOK: cluster.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
16 plays in cluster.yml

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
META: ran handlers  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.043) 0:00:00.043 \*\*\*\*\*\*\*\*\*  
META: ran handlers  
META: ran handlers  
[WARNING]: Could not match supplied host pattern, ignoring: bastion

PLAY [bastion[0]] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: no hosts matched

PLAY [k8s-cluster:etcd] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
META: ran handlers  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.037) 0:00:00.081 \*\*\*\*\*\*\*\*\*  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.049) 0:00:00.130 \*\*\*\*\*\*\*\*\*  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.048) 0:00:00.178 \*\*\*\*\*\*\*\*\*  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.051) 0:00:00.230 \*\*\*\*\*\*\*\*\*  
Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.024) 0:00:00.254 \*\*\*\*\*\*\*\*\*

Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.021) 0:00:00.275 \*\*\*\*\*\*\*\*\*

Thanks for the help,  
Ronen

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 1, 2020, 5:24am UTC](https://forum.ansible.com/t/ignore-imported-playbooks-completely-when-defined/32574/2 "2020-04-01T05:24:15Z")

</div>

> Hi,
> 
> I'm using ansible version 2.7.17 and combining multiple playbooks in one file.  
> One of my playbooks I'm running conditionally with when and a condition.  
> My problem is when my condition is false, I want ansible to completely ignore my playbook and not load anything related  
> to this playbook.  
> I tried using both import\_playbook and include, which seems to have similar results.  
> The call to the playbook looks like that:
> 
> - name: Include kubespray tasks  
> include: ../kubespray/cluster.yml  
> when: cluster\_installation
> 
> in my output you can see ansible run the handlers inside the ignored playbook (keeping for 2 more minutes):
> 
> PLAYBOOK: cluster.yml  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> 16 plays in cluster.yml
> 
> PLAY [localhost]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> META: ran handlers  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.043) 0:00:00.043 \*\*\*\*\*\*\*\*\*  
> META: ran handlers  
> META: ran handlers  
> [WARNING]: Could not match supplied host pattern, ignoring: bastion
> 
> PLAY [bastion[0]]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> skipping: no hosts matched
> 
> PLAY [k8s-cluster:etcd]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> META: ran handlers  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.037) 0:00:00.081 \*\*\*\*\*\*\*\*\*  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.049) 0:00:00.130 \*\*\*\*\*\*\*\*\*  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.048) 0:00:00.178 \*\*\*\*\*\*\*\*\*  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.051) 0:00:00.230 \*\*\*\*\*\*\*\*\*  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.024) 0:00:00.254 \*\*\*\*\*\*\*\*\*  
> Tuesday 31 March 2020 18:55:46 +0000 (0:00:00.021) 0:00:00.275 \*\*\*\*\*\*\*\*\*
> 
> Thanks for the help,  
> Ronen

Hello Ronen,

as far as I know that's not possible. Ansible will parse the role even if the condition evalulates to false.  
Also note that allows you to use the variables in the role, even if all tasks are skipped due to the condition.

Does it really run the handlers? I don't see no output indicating this.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Ronen\_Levinson](https://avatars.discourse-cdn.com/v4/letter/r/ecd19e/32.png) [@Ronen\_Levinson](https://forum.ansible.com/u/Ronen_Levinson)\
**Post date:** [April 1, 2020, 6:35am UTC](https://forum.ansible.com/t/ignore-imported-playbooks-completely-when-defined/32574/3 "2020-04-01T06:35:48Z")

</div>

I assumed from the: `META: ran handlers` in the output that it’s something related to the handlers.

It’s odd that only parsing takes 2 minutes, I know that kubespray is a big project, but 2 minutes just to parse files is a lot of time.
