Yes, been meaning to do that for some time, but haven't gotten around to properly cleaning it up etc. Happy to create a PR if you are interested -- for now, here's the rough version:
https://gist.github.com/cthiemann/220c128e298614a869f2 The filter_plugin returns the value of a dictionary that exists for a list of keys. Example: # vars file foo: Debian: bar Ubuntu: baz Gentoo: abc # Jinja template {{ foo|selectby(['Gentoo']) }} == abc {{ foo|selectby(['Debian', 'Ubuntu']) }} == bar {{ foo|selectby(['Ubuntu', 'Debian']) }} == baz The vars_plugin defines a variable for each host that's a list of ansible_distribution + version, ansible_os_family, etc. in descending order of specificity, and modifies the YAML parser to recognize dictionaries tagged !platform, which will be converted into Jinja templates using the |selectby filter. Example: # vars file foo: !platform Debian: bar Ubuntu: baz Gentoo: abc # Jinja template {{ foo }} == abc if ansible_os_family == 'Gentoo' {{ foo }} == bar if ansible_os_family == 'Debian' and not ansible_distribution == 'Ubuntu' {{ foo }} == baz if ansible_distribution == 'Ubuntu' The |selectby filter is a bit more complex than just this, it also transparently iterates over lists, so that these two are equivalent: foo1: - !platform Debian: bar - !platform Debian: barbara foo2: !platform - Debian: bar - Debian: barbara And it allows to define a default value: foo: !platform default-value:: Debian: override-value {{ foo }} == ('override-value' if ansible_os_family == 'Debian' else 'default-value') On Thursday, June 11, 2015 at 12:05:53 AM UTC+2, Brian Coca wrote: > > Any intent on sharing that vars plugin? it sounds like a nice way to > unify vars in a single by distro vs per distro file. > > > -- > Brian Coca > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/72f85f96-8833-4221-a11f-5ce000e95bb9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
