[英]Ansible error: "The Python 2 bindings for rpm are needed for this module"
我正在嘗試 pip 使用以下任務在我的 python3 環境中安裝需求文件
pip:
python3: yes
requirements: ./requirements/my_requirements.txt
extra_args: -i http://mypypi/windows/simple
我檢查了 ansible 在 controller 節點(RH7)上運行的版本,它是 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."}
我的 controller 節點正在運行 RH7。 目標是 centos7(由 vagrantfiles 提供)
現在有人知道如何解決這個問題嗎?
我在使用 yum 的“Amazon Linux 2”發行版中遇到了類似的問題,但在撰寫本文時不支持 dnf。
正如上面評論中提到的,我的問題出在 ansible 托管節點(運行 Amazon Linux 2 的 AWS EC2 實例)而不是 controller。
通過強制使用 python2 解決它,在 ansible 清單文件中為這組主機添加ansible_python_interpreter=/usr/bin/python2
,如以下代碼段所示:
[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 quick guide的這本劇本進行了嘗試。
---
- 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 代理后。)
$ 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.cfg
文件的inventory
條目設置為不存在的文件,則此錯誤消息可能會顯示。
調整
ansible-playbook
至
ansible-playbook -e ansible_python_interpreter=/usr/bin/python2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.