You could try to variablize the values of the module parameters into
os-specific vars files and then do conditional include statements based on
the os.
So like
---
- hosts: all
gather_facts: yes
tasks:
- include: "{{ ansible_distribution }}-{{ ansible_distribution_version
}}.yml"
- name: set up serial console
replace:
dest: /etc/inittab
regexp: "{{ serial_regex }}"
replace: "{{ serial_replace"
notify:
- telinit_q
handlers:
- name: telinit_q
command: "/sbin/telinit q"
Where you would have files named like debian-7.yml, etc. And within those
files you would have serial_regex/replace defined along with any other vars.
Does that help?
On Monday, March 23, 2015 at 6:42:55 PM UTC-4, Vince Skahan wrote:
>
> What's the preferred way to conditionally configure something if the 'how'
> changes from os to os, and version to version 'of' any particular os ?
>
> Here's an example - setting up a serial console on a SysVinit system
> (example - debian 7.8):
>
> ---
> - hosts: all
> gather_facts: yes
> tasks:
> - name: set up serial console
> replace:
> dest: /etc/inittab
> regexp: "^#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100$"
> replace: "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100"
> notify:
> - telinit_q
> handlers:
> - name: telinit_q
> command: "/sbin/telinit q"
>
>
> But that only works on debian-7 systems. I can limit it to debian-7 by
> inserting
>
>
> when:
> ansible_distribution == 'Debian' and
> ansible_distribution_version == '7'
>
>
> But that doesn't handle centos-5 which has a slightly different
> search/replace needed....or centos-7 which uses systemd, and so on.
>
> I guess I'm struggling with how to have a set (tree?) of plays for
> task-ABC that are known good, but only using them when the os/version say
> to do it that way.
>
> Is the preferred way to include .yml files based on distribution/version
> values discovered at runtime ? Examples ?
>
>
>
>
--
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/0fe25e82-3e9d-43e7-bd5e-70c69017e35b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.