Davide Martorana
Davide Martorana

Reputation: 729

Ansible package vs yum module

I am a newbie in the Ansible world. I have already created some playbook and I am getting more and more familiar with this technology by the day. In my playbooks I have always used the command yum to install and manage new packages, but recently I found out about another command package that claims to be OS independent.

Thus my question: What is the difference between them?

In particular, if I create a role and a playbook that I know that will be executed in RHEL environment (where yum is the default package manager), which advantage do I get from using the command package rather than yum?

Thanks in advance for your help.

Upvotes: 15

Views: 14369

Answers (2)

bodo
bodo

Reputation: 847

Ansible package module is more general but looks like you still have to handle differences in package names. From package module

# This uses a variable as this changes per distribution.
- name: remove the apache package
  package:
    name: "{{ apache }}"
    state: absent

In this case package name for:

  • RHEL - httpd
  • Debian/Ubuntu - apache2

so {{ apache }} variable must be set according to the OS.

Upvotes: 10

deepak
deepak

Reputation: 1151

Ansible package module autodetect your OS default package manager (e.g yum, apt) from existing facts.

The fact environment variable which stores is "ansible_pkg_mgr".

Here is a command for same. ansible localhost -m setup | grep ansible_pkg_mgr.

If you are using multiple OS in your environment, then instead of specifying package manager you should use package over yum or apt.

Upvotes: 11

Related Questions