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 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:
- RHEL - httpd
- Debian/Ubuntu - apache2
so {{ apache }} variable must be set according to the OS.
(newbie) why different package managers (apt: or yum:)
Yum/DNF detection depends upon RHEL major version
Why is my Ansible playbook using dnf even when yum is explicitly specified? - Stack Overflow
yum module
good afternoon,
why ansible designers choose to implement different modules for different package managers (ex: apt: for debian and yum: for redhat) and so force use to create different platbooks, instead of creating some sort of unique instruction in ansible to install a package, leaving to ansible the task to understand the guest os (debian, redhat...) and use the right pkg manager?
thank you for your time.
Hi,
in Redhat we can install packages from modules by typing
"sudo dnf module install mysql "
how can i use this "module" in ansible? Couldn`t find any examples
You can install a module (which is essentially a group of packages) by adding a @ prior to the name of the module to the name parameter of the Ansible dnf module. It can be used like this:
- name: install the 'Development tools' package group
dnf:
name: '@Development tools'
state: present
Semantics warning: Ansible uses the term "Module" to describe a specific command set or functionality. DNF/Yum4 uses the term "module" to describe groups of packages, features, and software vendors. These can easily confuse things in this question.
Per the official documentation for Ansible 2.9, there is no (documented) support for the DNF/Yum4 "modules" capabilities.
If you specifically need to use the 'modules' switch with DNF/Yum4, you can do so using the ansible command or shell modules, depending on how you use it. Some example code:
- name: Use dnf command to install postgresql 9.6 client
command: dnf module install postgresql:9.6/client
This task will enable the postgreql module, 9.6 stream, and install the packages tagged as part of the 'client' profile.
Alternatively, you could try the following notation with the dnf module in Ansible; I have not tested it and cannot say if it will work or if Ansible can properly interpret the special characters.
- name: Use the ansible dnf_module to install postgresql 9.6 client
dnf:
name: '@postgresql:9.6/client'
state: present
According to RHEL8 documentation, yum4/dns accepts this notation without explicitly calling the "module" switch. (Example near the bottom of section 4.6)