"I understand that we can use something like 'when: ansible_os_family == "RedHat"' or the like, but when we have 400 CentOS hosts and 200 Ubuntu hosts, that's a lot of "skipping" messages"
Use this module: http://docs.ansible.com/group_by_module.html - hosts: all tasks: - group_by: key=os-{{ ansible_os_family }} - hosts: os-RedHat tasks: - # Red Hat things Also be sure to use "with_items" where possible to group package installs into a minimum of transactions, which will save considerable install time. On Tue, Aug 19, 2014 at 4:22 AM, KSS <[email protected]> wrote: > Hi, I need to install some packages across different Linux distros > (mainly CentOS/Redhat and Ubuntu right now). However, since there isn't a > unified package manager (at least not bundled with core), I'm trying to > find the best way to do this. > > I understand that we can use something like 'when: ansible_os_family == > "RedHat"' or the like, but when we have 400 CentOS hosts and 200 Ubuntu > hosts, that's a lot of "skipping" messages (I'm aware these can also be > suppressed in the main config file). We have playbooks that run against > certain groups of hosts (these groups can contain multiple distros), so I'm > not sure that using group_by is the best option either as, from my > understanding, I'd have to have a 'group_by' in each of those playbooks and > for each distro. > > For example, we have an 'ntp' role which basically just installs the ntp > package, drops in the ntp config using template and ensures it's started > (we have similar roles for snmp, ssmtp etc.). > > I came across a previous post with an answer from Michael DeHaan > suggesting using the following action (although Michael does state that > it's a bad idea), however, this no longer appears to work; > > Using task; > > --- > ## > # Install and configure NTPD > > - name: Gather OS Specific Variables > include_vars: "{{ item }}" > with_first_found: > - "../vars/{{ ansible_distribution }}-{{ > ansible_distribution_version }}.yml" > - "../vars/{{ ansible_distribution }}.yml" > - "../vars/{{ ansible_os_family }}.yml" > - "../vars/defaults.yml" > > - name: Ensure NTP is Installed > action: "{{ ansible_pkg_mgr }} name=ntp state=present" > tags: ntp > > - name: Copy NTP Configuration File > template: src=../templates/ntp.conf.j2 dest=/etc/ntp.conf > notify: > - restart ntpd > tags: ntp > > - name: Start NTPD > service: name="{{ ntp_service }}" state=started enabled=true > tags: ntp > > Results in; > > TASK: [ntp | Ensure NTP is Installed] > ***************************************** > <XX.XX.XX.XX> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO XX.XX.XX.XX > <XX.XX.XX.XX> REMOTE_MODULE {{ ansible_pkg_mgr }} name=ntp state=present > fatal: [XX.XX.XX.XX] => module {{ not found in > /usr/share/ansible/system:/usr/share/ansible/commands:/usr/share/ansible/messaging:/usr/share/ansible/cloud:/usr/share/ansible/notification:/usr/share/ansible/net_infrastructure:/usr/share/ansible/inventory:/usr/share/ansible/utilities:/usr/share/ansible/internal:/usr/share/ansible/files:/usr/share/ansible/packaging:/usr/share/ansible/database:/usr/share/ansible/source_control:/usr/share/ansible/network:/usr/share/ansible/web_infrastructure:/usr/share/ansible/monitoring:/usr/share/ansible > > FATAL: all hosts have already failed -- aborting > ---------------- > > Ansible Version: 1.6.10 > OS: CentOS6.5 > > We have a few hundred servers for which puppet is used for config > management and a hundred or so being managed using Salt (different > departments hence the different tools), and the unified package managers > seem to work well in those tools. Are there any plans to have a module in > Ansible, even if it's just a simple wrapper to call the appropriate module, > yum or apt or whatever, so these kind of playbooks look a bit better and > make it easier where multiple distros are used. So, for example, in this > case I'd just need something like; > > - name: Ensure NTP is Installed > pkg: name=ntp state=present > tags: ntp > > ...and the 'pkg' module works out the correct package module to call. I > know the individual package modules do more than just install and remove > packages but I feel, and maybe I'm the only one, that something like this > would make things simpler and cleaner looking. > > Anyway, does anyone have any recommendations to achieve this in the mean > time? > > Thanks. > > -- > 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/90fc7427-cca3-434f-9c95-04b1e740281f%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/90fc7427-cca3-434f-9c95-04b1e740281f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CA%2BnsWgxuw0HUYC54a3U_g-NVHOnhvzpybqSScB25xWZxCQFjng%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
