Here’s the next feature I am going to add to play books – “only_if”.
- name: foo
action: modulename
only_if: some conditional
This will allow conditional execution of steps, on a host by host basis, based on facts or ohais (is that even the proper plural of ohai? Inquiring minds want to know).
Ex:
- name: package that should only be installed on CentOS
action: yum pkg=foo ensure=installed
only_if: $facter_operatingsystem == ‘Debian’
Which hosts actually execute the step, and which skip the step, will be logged in playbook output.
My goal here, with play books, is to keep the levels of indentation really flat, and the syntax as less like a programming language as possible. This is to make everything extremely auditable for compliance and maintaince purposes, as well as to keep the barrier to entry to the system super small – not having a lot of obscure syntax and remembering when to indent this, or not indent that.
In a very large example, imagine:
- import: foo.yml
- import: ntp.yml
- import: fixup.yml
Suppose in fixup.yml we have a step that should ONLY run on Debian OSes with an operating system version of X.
This will make all that possible, but the logic is not listed in the main playbook, it’s defined well away in the import, so the main playbook is extremely clean, just containing a list of what composes that particular host group in the playbook.
Thus, something really simple (think in Puppet of site.pp) that normally just says “this is a foo, this is a bar”, +1 level of indirection is all you need, rather than having a complex series of files that import other files in somewhat hard to visualize ways.
After that, a brief timeout for some much-deserved refactoring… we’ve grown slightly over 1000 lines in the core (according to slocount), and that can be much shorter to make things easier to contribute to
–Michael