Check if a software package is installed

Hello everyone,

I am quite new to Ansible, and I think it is much easier to use than e.
g. Puppet.

I have to make sure that software package A is installed on a host, if
software package B is not.

Since I use this role on SLES: is there any chance to use e.g. the
zypper modukle for that purpose?

Currently, I invoke a command to check if B is installed, and if it is
not, I call the zypper module to make sure A is installed:

=== snip ===
- name: query rubygem-facter
  command: rpm -q rubygem2.1-rubygem-facter
  ignore_errors: true
  register: ch_rpm2
  failed_when: ch_rpm2.rc > 1
  changed_when: false

- name: install facter
  zypper: name=facter state=present
  when: ch_rpm2|failed
=== pins ===

Is there any more ansible-style way to get this done?

I can't simply install facter, since it is an older version. The attempt
to install facter on a host where rubygem2.1-rubygem-facter is already
installed causes an error, and I do not like avoidable errors in my
roles, they are often misleading :wink:
OTOH, not each system can fulfill the dependencies for
rubygem2.1-rubygem-facter - like Ruby 2.1. SLES 11 does not have this as
standard, and its annoying to add it here, because it almost always
causes troubles with the ruby-based software on the host.

Regards,
Werner

Is there any more ansible-style way to get this done?

I would be interested in this, too.

OTOH, not each system can fulfill the dependencies for
rubygem2.1-rubygem-facter - like Ruby 2.1. SLES 11 does not have this as
standard, and its annoying to add it here, because it almost always
causes troubles with the ruby-based software on the host.

If this is somehow OS-version related (SLE11 no, SLE12 yes, ...), you
could simply use a group_vars file with a variable, and use that to
check and/or install:

group_vars/SLE11.yml:

facter_package: facter

group_vars/SLE12.yml:

facter_package: rubygem2.1-rubygem-facter

Role/Playbook/Task/...:

- name: install whatever fits
  zypper: name="{{facter_package }}" state=present

Johannes