# How to exclude openvz guests?

**URL:** <https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802>\
**Category:** Ansible Project\
**Created:** [March 19, 2014, 4:13am UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802 "2014-03-19T04:13:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilya](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@Ilya](https://forum.ansible.com/u/Ilya)\
**Post date:** [March 19, 2014, 4:13am UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/1 "2014-03-19T04:13:16Z")

</div>

I want to exclude all openvz guests the task being run. I’ve tried “when: not (ansible\_virtualization\_type == ‘openvz’ and ansible\_virtualization\_role == ‘guest’)” and some variations, but it doesn’t work (“error while evaluating conditional”), seemingly because the variables are not defined. So how can I actually do it?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 19, 2014, 4:17am UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/2 "2014-03-19T04:17:45Z")

</div>

you can put them into a group, either statically or dynamically with group\_by (in a pre play).

then in the play that runs those tasks you can hosts: “all:!openvz”, or if only for a task

when: inventory\_hostname not in groups[‘openvz’]

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 19, 2014, 4:18am UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/3 "2014-03-19T04:18:36Z")

</div>

otherwise, add ‘is defined’ to the vars you are checking.

---

<div class="post-metadata">

**Author:** ![Ilya](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@Ilya](https://forum.ansible.com/u/Ilya)\
**Post date:** [March 19, 2014, 4:28am UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/4 "2014-03-19T04:28:15Z")

</div>

I don’t know the values ahead, so I can’t use a static group. **Adding** “is defined” won’t change the fact that it fails due to variable being undefined. I understand that it’s the case for dynamic grouping based on a variable, as well.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 19, 2014, 2:01pm UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/5 "2014-03-19T14:01:28Z")

</div>

“ **Adding** “is defined” won’t change the fact that it fails due to variable being undefined.”

Don’t believe that’s true. Conditionals will still short circuit fine.

Also {{ x | default(‘none’) }} == ‘open\_vz\_whatever’

may also be an option

---

<div class="post-metadata">

**Author:** ![Ilya](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@Ilya](https://forum.ansible.com/u/Ilya)\
**Post date:** [March 19, 2014, 3:45pm UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/6 "2014-03-19T15:45:05Z")

</div>

Yes, I think I confused it with another software that had a similar issue. Thanks.

This is what seems to work for me:  
not\_openvz\_guest: ansible\_virtualization\_type is not defined or (ansible\_virtualization\_type is defined and not (ansible\_virtualization\_type == ‘openvz’ and ansible\_virtualization\_role == ‘guest’))

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [March 19, 2014, 3:47pm UTC](https://forum.ansible.com/t/how-to-exclude-openvz-guests/14802/7 "2014-03-19T15:47:39Z")

</div>

shorter version

not\_openvz\_guest: ansible\_virtualization\_type is not defined or not  
(ansible\_virtualization\_type == 'openvz' and ansible\_virtualization\_role ==  
'guest')
