conditionals in meta includes

92 views
Skip to first unread message

Michael Dur

unread,
Jul 25, 2014, 3:04:28 PM7/25/14
to ansible...@googlegroups.com
I have a role which is just a meta playbook for installing many packages.
I only want these to run once during an ansible run  since interacting with the package manager is slow.
I thought I'd register a variable and check it, however I'm getting an error.

TASK: [feature/zypper | remove non-seas repos] ******************************** 
fatal: [tr808.seas.upenn.edu] => error while evaluating conditional: ( common_has_executed == 'false')

Here the relevant files:

common/tasks/main.yml
---
- name: log common status
  set_fact:  common_has_executed = 'true'

common/meta/main.yml
---
allow_duplicates: no
dependencies:

  - { role: feature/rc.firewall, when: ( common_has_executed == 'false') }
  - { role: feature/perl, when: ( common_has_executed == 'false') }
  - { role: feature/python, when: ( common_has_executed == 'false') }
  - { role: feature/ruby, when: ( common_has_executed is == 'false') }

Michael Dur

unread,
Jul 25, 2014, 3:29:12 PM7/25/14
to ansible...@googlegroups.com
I've discovered two things I'll post here:

1. For the time being you can toggle failing on undefined variables in the ansible config

2. It is better to use 'is defined' or 'is not defined' rather than comparison in this use case. 

Michael DeHaan

unread,
Jul 25, 2014, 3:30:38 PM7/25/14
to ansible...@googlegroups.com
The correct pattern would be:

when: foo is defined and foo



--
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/a6232724-68f4-4de6-84b8-13c26e090219%40googlegroups.com.

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

Michael Dur

unread,
Jul 25, 2014, 3:50:26 PM7/25/14
to ansible...@googlegroups.com
Good.  And since I'm suppressing additional runs of this playbook, is there a way to suppress the output as well (that is the many lines of skipped stuff).

Michael DeHaan

unread,
Jul 25, 2014, 4:07:09 PM7/25/14
to ansible...@googlegroups.com
The best way to avoid skipped messages is to use things like "group_by" when relevant, so you don't run RedHat specific tasks on Debian systems and have to watch the skipped.

When that is not practical, there is the following setting:




Reply all
Reply to author
Forward
0 new messages