首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ubuntu18.04上安装可安装的2.9+并利用python3?

如何在ubuntu18.04上安装可安装的2.9+并利用python3?
EN

Stack Overflow用户
提问于 2020-03-04 09:42:51
回答 4查看 19.2K关注 0票数 7

我试图在Ubuntu仿生(18.04 LTS)上安装最小的ansible 2.9.x。

最后的目标是在每次提交时构建新的磁盘映像(使用packer),并希望进程尽可能快。

使用默认Ubuntu ansible

默认情况下在仿生是2.5.x中。

这太旧了,所有的ansible脚本都是为2.9+编写的。

使用官方PPA

使用推荐安装方法建议在/etc/apt/sources.list中添加以下行

代码语言:javascript
复制
deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main

并运行以下命令:

代码语言:javascript
复制
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
$ sudo apt update
$ sudo apt install ansible

但它仍然需要python2包:

代码语言:javascript
复制
$ sudo apt install ansible
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-asn1crypto
  python-cffi-backend python-crypto python-cryptography python-enum34 python-httplib2
  python-idna python-ipaddress python-jinja2 python-markupsafe python-minimal
  python-paramiko python-pkg-resources python-pyasn1 python-setuptools python-six
  python-yaml python2.7 python2.7-minimal sshpass
Suggested packages:
  python-doc python-tk python-crypto-doc python-cryptography-doc
  python-cryptography-vectors python-enum34-doc python-jinja2-doc python-gssapi
  python-setuptools-doc python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  ansible libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python
  python-asn1crypto python-cffi-backend python-crypto python-cryptography python-enum34
  python-httplib2 python-idna python-ipaddress python-jinja2 python-markupsafe
  python-minimal python-paramiko python-pkg-resources python-pyasn1 python-setuptools
  python-six python-yaml python2.7 python2.7-minimal sshpass
0 upgraded, 25 newly installed, 0 to remove and 33 not upgraded.
Need to get 11.3 MB of archives.
After this operation, 83.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]

使用pip

这是我目前的方法,但是安装pip3和安装移动式pip是另一个额外的步骤:

代码语言:javascript
复制
$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot
  libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libpython3-dev libpython3.6-dev libquadmath0 libstdc++-7-dev libtsan0 libubsan0
  linux-libc-dev make manpages-dev python-pip-whl python3-crypto python3-dev python3-distutils python3-keyring python3-keyrings.alt python3-lib2to3
  python3-secretstorage python3-setuptools python3-wheel python3-xdg python3.6-dev
Suggested packages:
  binutils-doc cpp-doc gcc-7-locales debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib autoconf automake libtool flex bison gdb gcc-doc
  gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg
  glibc-doc bzr libstdc++-7-doc make-doc python-crypto-doc gnome-keyring libkf5wallet-bin gir1.2-gnomekeyring-1.0 python-secretstorage-doc python-setuptools-doc
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dh-python dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot
  libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libpython3-dev libpython3.6-dev libquadmath0 libstdc++-7-dev libtsan0 libubsan0
  linux-libc-dev make manpages-dev python-pip-whl python3-crypto python3-dev python3-distutils python3-keyring python3-keyrings.alt python3-lib2to3 python3-pip
  python3-secretstorage python3-setuptools python3-wheel python3-xdg python3.6-dev
0 upgraded, 57 newly installed, 0 to remove and 33 not upgraded.
Need to get 85.3 MB of archives.
After this operation, 248 MB of additional disk space will be used.
Do you want to continue? [Y/n]

...which为封隔器进程增加了不必要的时间:(

有什么暗示吗?

Ubuntu18.04附带了已经安装的python3,ansible可以很容易地配置为使用python3。有人知道如何在不需要安装python2或pip3的情况下安装Anble2.9吗?

EN

回答 4

Stack Overflow用户

发布于 2020-04-23 19:35:26

我也遇到过同样的问题。在我的情况下,由于AWX的要求,必须在2.9.+中.如果您在Ubuntu18.04,您可以遵循以下步骤:

代码语言:javascript
复制
$ sudo apt install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt update

$ sudo apt install ansible

就这样。

代码语言:javascript
复制
$ ansible --version
  |___ ansible 2.9.7

注意:我建议你在Unix & Linux中提出这样的问题

票数 5
EN

Stack Overflow用户

发布于 2020-10-06 11:41:53

正如在问题上提到的,目前建议Ubuntu用户使用Debian存储库。可以直接下载这里,并使用以下方法安装下载的deb

代码语言:javascript
复制
sudo apt-get install ./ansible_x.y.z_all.deb

这将在不安装python2的情况下安装ansible。我已经在Ubuntu19.10上成功地测试了这个。

票数 2
EN

Stack Overflow用户

发布于 2020-07-23 05:53:28

我也遇到了同样的问题。当我用

sudo apt install ansible

ansible与Python2.7.x一起安装

我卸载了所有的东西,并使用pip安装了ansible。现在,当我做ansible --版本的时候

配置文件=/etc/ansible.cfg配置模块搜索路径=‘/root/. ansible /plugins/模块’,‘/usr/share/ ansible /plugins/模块’ansible python模块位置= /usr/local/lib/python3.6/dist-packages/ansible可执行位置= /usr/local/bin/ansible python版本= 3.6.9 (默认值,2020年4月18日,01:56:04) GCC 8.4.0

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60523088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档