大网数据广告活动
服务器运维问答

What is the prefered method to install Python with Ansible on CentOS 8

· 52CE 我爱测

CentOS 8 does not always come with Python pre-installed, and so Ansible will fail running on the remote machine until it's been installed. However in a classic Chicken/Egg, you can't use the Ansible dnf module to install Python. …

问题原文

原帖链接 · oucil · CC BY-SA 4.0

CentOS 8 does not always come with Python pre-installed, and so Ansible will fail running on the remote machine until it's been installed. However in a classic Chicken/Egg, you can't use the Ansible dnf module to install Python.

I've been using:

- name: Install Python 3
  raw: dnf -y install python3

However the problem with this is that I either have to set changed_when: false or it will always return a changed state. I'd like the state reported properly if it's possible.

I found easy_install however this appears to only deal with Python Libraries, and not Python itself. Is there a built-in way to handle this or is raw: the only option?

已采纳解答

原帖链接 · Henrik Pingel · CC BY-SA 4.0

Yes, the raw module is the preferred way to install Python with Ansible. You might want to include some other necessary packages for Ansible as well:

- name: Bootstrap a host without python2 installed
  raw: dnf install -y python2 python2-dnf libselinux-python

easy_install depends on Python. There is no way around raw when Python is not present. Usually I use this raw task as part of a special bootstrapping playbook executed only once. Another reason to define this task outside the other roles and plays is that you cannot use fact gathering when Python is not present on the target system.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。