3

我想在 Debian 测试中使用 Ansible 2.7.7 安装 debian 软件包(还)

我尝试执行这个简单的任务:

  tasks:
  - name: install basic packages
    apt:
      name: ['mc', 'htop', 'strace','sudo','screen','lshw', 'postfix', 'etckeeper']
      state: present


但是安装失败并出现奇怪的消息:

TASK [install basic packages] *********************************************************************************
fatal: [webserver.vitexsoftware.cz]: FAILED! => {"changed": false, "msg": "Could not import python modules: apt, apt_pkg. Please install python-apt package."}
        to retry, use: --limit @/home/vitex/Projects/VitexSoftware/Ansible/playbooks/orchestrate.retry

apt 所需的 python 包安装为python3-apt

vitex@webserver:~/Projects/VitexSoftware/DockerTools$ aptitude search python | grep '\-apt'
i A python-apt-common - Python interface to libapt-pkg (locales)
p  python-apt-dev - Python interface to libapt-pkg (development files)
p  python-apt-doc - Python interface to libapt-pkg (API documentation)
i  python3-apt - Python 3 interface to libapt-pkg
p  python3-apt-dbg - Python 3 interface to libapt-pkg (debug extension)
v  python3-apt-dbg:any - 
v  python3-apt:any - 
p  python3-aptly - Aptly REST API client and useful tooling - Python 3.x
v  python3.9-apt - 
v  python3.9-apt-dbg - 
v  python3.9-apt-dbg:any - 
v  python3.9-apt:any - 

github上有一个未解决的未解决问题:https ://github.com/ansible/ansible/issues/73535这不会以某种方式帮助我。

如何像在 Debian 10 上一样工作?

4

2 回答 2

2

在 hosts 文件中指定 python3 作为解释器

[webservers]
webserver.vitexsoftware.cz ansible_host=10.11.56.210 ansible_python_interpreter=/bin/python3

完成它的工作:

TASK [install basic packages] ************************************************************************************************************************************************************************************************************************************************
changed: [webserver.vitexsoftware.cz]
于 2021-05-29T10:36:34.827 回答
0

对我有用的另一个选项是从目标主机中删除 python2。

于 2022-01-10T21:40:44.343 回答