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.
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. 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.
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.
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.
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
.
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:
so {{ apache }}
variable must be set according to the OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With