Hi Christian,
I didn't get how did you do the OS specific package installation. I've
ended up with a temporary solution:
- name: install python-passlib
action: "{{ ansible_pkg_mgr }} name={{ item.name }}"
with_items:
- { os: Gentoo, name: dev-python/passlib }
when: ansible_os_family == item.os
But I do like the way you've shown. Could I possibly ask you to give me an
example with the 'action' module? And should it work in ansible 1.9?
On Thursday, June 11, 2015 at 1:39:57 AM UTC+3, Christian Thiemann wrote:
>
> 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/68f60a87-7f67-4a79-816b-207a05d8b29d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.