How to exclude openvz guests?

326 views
Skip to first unread message

Ilya Ivanov

unread,
Mar 19, 2014, 12:13:16 AM3/19/14
to ansible...@googlegroups.com
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?

Brian Coca

unread,
Mar 19, 2014, 12:17:45 AM3/19/14
to ansible...@googlegroups.com
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']

Brian Coca

unread,
Mar 19, 2014, 12:18:36 AM3/19/14
to ansible...@googlegroups.com
otherwise, add 'is defined' to the vars you are checking.

Ilya Ivanov

unread,
Mar 19, 2014, 12:28:15 AM3/19/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Mar 19, 2014, 10:01:28 AM3/19/14
to ansible...@googlegroups.com
"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




On Wed, Mar 19, 2014 at 12:28 AM, Ilya Ivanov <bear...@gmail.com> wrote:
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.

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d430cf52-b221-4f69-8797-f84c245b0938%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ilya Ivanov

unread,
Mar 19, 2014, 11:45:05 AM3/19/14
to ansible...@googlegroups.com
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'))

Brian Coca

unread,
Mar 19, 2014, 11:47:39 AM3/19/14
to ansible...@googlegroups.com
shorter version

not_openvz_guest: ansible_virtualization_type is not defined or not (ansible_virtualization_type == 'openvz' and ansible_virtualization_role == 'guest')


--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno
Reply all
Reply to author
Forward
0 new messages