Ansible 错误:“此模块需要 rpm 的 Python 2 绑定"; [英] Ansible error: "The Python 2 bindings for rpm are needed for this module"

查看:363
本文介绍了Ansible 错误:“此模块需要 rpm 的 Python 2 绑定";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下任务在我的 python3 环境中 pip 安装需求文件

Im trying to pip install a requirements file in my python3 environment using the following task

pip:
  python3: yes
  requirements: ./requirements/my_requirements.txt
  extra_args: -i http://mypypi/windows/simple

我检查了控制器节点 (RH7) 上运行的 ansible 版本是 3.6.8

I checked which version ansible is running on the controller node (RH7) and it's 3.6.8

ansible-playbook 2.9.9
  config file = None
  configured module search path = ['/home/{hidden}/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Jun 11 2019, 15:15:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
No config file found; using defaults

但是我收到以下错误:

fatal: [default]: FAILED! => {"changed": false, "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module
instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}

我的控制器节点正在运行 RH7.目标是centos7(由vagrantfiles提供)

My controller node is running RH7. The targets are centos7 (provisioned by vagrantfiles)

现在有人知道如何解决这个问题吗?

Does anyonek now how to solve this?

推荐答案

我在使用Amazon Linux 2"时遇到了类似的问题.使用 yum 但在撰写本文时不支持 dnf 的发行版.

I had a similar problem with the "Amazon Linux 2" distribution that uses yum, but does not support dnf as of this writing.

如上述评论中所述,我的问题出在 ansible 托管节点(运行 Amazon Linux 2 的 AWS EC2 实例)而不是控制器中.

As mentioned in the comments above, my problem was in the ansible-managed nodes (AWS EC2 instances running Amazon Linux 2) and not in the controller.

通过强制使用python2解决了这个问题,在ansible清单文件中为这组主机添加了ansible_python_interpreter=/usr/bin/python2,如下代码片段:

Solved it by imposing the use of python2, adding ansible_python_interpreter=/usr/bin/python2 for this group of hosts in the ansible inventory file, as in the following snippet:

[amz_linux]
server2 ansible_host=ec2-xx-yy-zz-pp.eu-west-1.compute.amazonaws.com


[amz_linux:vars]
ansible_user=ec2-user
ansible_python_interpreter=/usr/bin/python2

使用改编自 Redhat 快速指南.

---
- hosts: amz_linux
  become: yes
  tasks:
   - name: install Apache server
     yum:
       name: httpd
       state: latest

   - name: enable and start Apache server
     service:
       name: httpd
       enabled: yes
       state: started

   - name: create web admin group
     group:
       name: web
       state: present

   - name: create web admin user
     user:
       name: webadm
       comment: "Web Admin"
       groups: web
       append: yes

   - name: set content directory group/permissions 
     file:
       path: /var/www/html
       owner: root
       group: web
       state: directory
       mode: u=rwx,g=rwx,o=rx,g+s

   - name: create default page content
     copy:
       content: "Welcome to {{ ansible_fqdn}} on {{ ansible_default_ipv4.address }}"
       dest: /var/www/html/index.html
       owner: webadm
       group: web
       mode: u=rw,g=rw,o=r

实际 ansible-playbook 运行(使用 ssh-add 将实例私钥添加到 ssh 代理后.)

Actual ansible-playbook run (after using ssh-add to add the instance private key to the ssh agent.)

$ ansible-playbook -i ansible/hosts ansible/apache_amz_linux.yaml 

PLAY [amz_linux] **********************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************
The authenticity of host 'ec2-xxxxxxxxxxx.eu-west-1.compute.amazonaws.com (xxxxxxxxxxx)' can't be established.
ECDSA key fingerprint is SHA256:klksjdflskdjflskdfjsldkfjslkdjflskdjf/sdkfj.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
ok: [server2]

TASK [install Apache server] **********************************************************************************************
changed: [server2]

TASK [enable and start Apache server] *************************************************************************************
changed: [server2]

TASK [create web admin group] *********************************************************************************************
changed: [server2]

TASK [create web admin user] **********************************************************************************************
changed: [server2]

TASK [set content directory group/permissions] ****************************************************************************
changed: [server2]

TASK [create default page content] ****************************************************************************************
changed: [server2]

PLAY RECAP ****************************************************************************************************************
server2                    : ok=7    changed=6    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 

这篇关于Ansible 错误:“此模块需要 rpm 的 Python 2 绑定";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆