--It seems to be called Dandified Yum
--Fedora's package management system (default from version 22)
--Can also be used with RHEL7 and CentOS7 (yum install -y dnf
)
--Installed as standard on RHEL8 and CentOS8
Simply put, dnf
is the successor to yum
, and from CentOS 8 it defaults to dnf
instead of yum
.
You can use the yum
command in CentOS8, but it's just a symbolic link to dnf
.
Support for Python 2.X ended on January 1, 2020.
--yum only works with python2.X --dnf works with python 2.x or 3.X
So from now on, dnf
will become the mainstream.
Install dnf in the CentOS 7.X Docker container.
[dnfuser@localhost ~]$ docker run -it --rm centos:7 bash
[root@3b4a088d7e6f /]# yum update -y
[root@3b4a088d7e6f /]# yum install -y epel-release
[root@3b4a088d7e6f /]# yum install -y dnf
[root@3b4a088d7e6f /]# head -n1 /usr/bin/dnf
#!/usr/bin/python2
Apparently CentOS 7.X's dnf
is running on python 2.X.
I tried it after installing python3.X, but dnf
becomes 2.X.
https://docs.ansible.com/ansible/latest/modules/dnf_module.html
If the interpreter is Python 2.X, you can install it easily.
playbook.yml
- name: Install epel-release
yum:
name: epel-release
state: present
become: yes
- name: Install dnf
yum:
name: dnf
state: present
become: yes
ansible.cfg
[default]
ansible_python_interpreter=/usr/bin/python3
As mentioned above, if you are using the Python 3.X interpreter by default, you will need to force it back to 2.X.
playbook.yml
- name: Install dnf for Centos7
block:
- name: Change interpreter
set_fact:
ansible_python_interpreter: "/usr/bin/python"
- name: Install epel-release
yum:
name: epel-release
state: present
become: yes
- name: Install dnf
yum:
name: dnf
state: present
become: yes
when:
- ansible_distribution_major_version | float < 8
The interpreter will be 2.X for subsequent tasks as well.
In Ansible 2.12 ver., The behavior of the default interpreter seems to change. (Maybe Python 3.X will be the preferred choice)
reference) https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html https://rheb.hatenablog.com/entry/ansible_interpreter_discovery
In the current ver. (2.9), / usr / bin / python
is specified by default, so the Python ver. Used may differ depending on the OS.
The best practices for those who can't wait for 2.12 ver. And want to use the dnf
command are as follows.
/ usr / bin / python
and continue to use Python 2.XFor those who say "Python 2.X is fine", you can use the default interpreter.
** Specify the Python 2.X interpreter in inventory for the CentOS 7.X host **
inventory.yml
all:
children:
centos7:
hosts: centos7-1
vars:
ansible_python_interpreter: /usr/bin/python # /usr/bin/python2 is also OK
If only CentOS7 is grouped, it seems easy to implement.
** Force the interpreter to change to 2.X in the playbook **
playbook.yml
- name: Change interpreter
set_fact:
ansible_python_interpreter: /usr/bin/python
By the way, I'm using this in case Python 3.X becomes the default.
Recommended Posts