On 25 August 2014 17:00, Anand Buddhdev <[email protected]> wrote:

> Hello ansible folk,
>
> I have a custom role called "firewall" that I currently use with CentOS 6.
> It managed the ip(6)tables rules files and reloads iptables as needed.
>
> Now I have a CentOS 7 server, on which firewalling is done by firewalld,
> so all my tasks and handlers and everything has to change. I was looking
> for a way to use the same role to work with both CentOS 6 and 7. I wanted
> to have:
>
> roles/
>   firewall/
>     tasks/
>       main.yml
>       CentOS6.yml
>       CentOS7.yml
>
> And then in main.yml, have something like:
>
> - include:
> '{{ansible_distribution}}{{ansible_distribution_major_version}}.yml'
>
> However, this is not allowed, as I discovered in the documentation.
>
> Is there any way I can keep a single role, and make it work simply with
> both OS versions?
>
>
I approach this with conditional includes

- include: centos6.yml
  when: ansible_distribution == "CentOS" and
ansible_distribution_version|int == 6
- include: centos7.yml
  when: ansible_distribution == "CentOS" and
ansible_distribution_version|int == 7

The 'int' filter may not actually be required. It might look inelegant but
it's very clear to read. The only issue for me is that ansible-playbook
displays a skipped status for each task it doesn't run for a host instead
of just ignoring them.

-- 
Tom Bamford

*@Planet*
ATPLANET (Pty) Ltd
atplanet.co.za

Cell: +27 (0)79-095-7112
Fax: +27 (0)86-599-1310

-- 
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/CAAnNz0NwzZm%3Dvy%2BNoFOCWeTUwtQLUvXX_g7xtLLyCv0V7Y6Avw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to