Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible package vs yum module

Tags:

ansible

I am a newbie in 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 an 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.

like image 313
Davide Martorana Avatar asked Feb 20 '18 09:02

Davide Martorana


People also ask

What is Ansible Yum module?

What is Ansible yum Module? Ansible yum module is used to manage packages using the yum package manager on CentOS and RHEL based Linux distributions including, RHEL, CentOS, Fedora, etc. You can perform all the basic package management operations including install, remove and update the packages using the yum module.

Do not install packages in Ansible?

Do not install packages. This module supports yum (as it always has), this is known as yum3 / YUM3 / yum-deprecated by upstream yum developers. As of Ansible 2.7+, this module also supports YUM4, which is the "new yum" and it has an dnf backend. By default, this module will select the backend based on the ansible_pkg_mgr fact.

Does Ansible automation come with red hat?

If you are a Red Hat customer, refer to the Ansible Automation Platform Life Cycle page for subscription details. This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name package even without specifying the collections: keyword.

What is the default action for a module in Yum?

Default is None, however in effect the default action is present unless the autoremove option is enabled for this module, then absent is inferred. Force yum to check if cache is out of date and redownload if needed. Has an effect only if state is present or latest. When using latest, only update installed packages. Do not install packages.


Video Answer


2 Answers

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.

like image 87
deepak Avatar answered Oct 27 '22 03:10

deepak


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.

like image 21
bodo Avatar answered Oct 27 '22 04:10

bodo