python-3.x - 如何在 ubuntu 18.04 上安装 ansible 2.9+ 并使用 python3?

标签 python-3.x ansible ubuntu-18.04 ansible-2.x

我正在尝试在 Ubuntu Bionic (18.04 LTS) 上安装最小的 ansible 2.9.x。

最终目标是在每次提交时构建新的磁盘镜像(使用打包程序),并希望该过程尽可能快。

使用默认的 Ubuntu ansible

bionic is 2.5.x 中默认 ansible .

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

使用官方 PPA

使用 recommended way to install建议将以下行添加到 /etc/apt/sources.list :

deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main

并运行以下命令:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
$ sudo apt update
$ sudo apt install ansible

但它仍然需要 python2 包:
$ 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]

使用点子

这是我目前的方法,但先安装 pip3,然后 installing ansible via pip是另一个额外的步骤:
$ 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]

...这给打包过程增加了不必要的时间:(

任何提示?

Ubuntu 18.04 已经安装了 python3,ansible 可以很容易地配置为使用 python3。
有谁知道如何在不需要安装 python2 或 pip3 的情况下安装 ansible 2.9 的方法?

最佳答案

我遇到了同样的问题。在我的情况下,由于 AWX 要求,必须使用 2.9.+ ......如果您使用的是 Ubuntu 18.04,您可以按照以下步骤操作:

$ sudo apt install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt update

$ sudo apt install ansible

就是这样。

$ ansible --version
  |___ ansible 2.9.7

注意:我建议您在 Unix & Linux 中提出此类问题

关于python-3.x - 如何在 ubuntu 18.04 上安装 ansible 2.9+ 并使用 python3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60523088/

相关文章:

python - 捕获上下文管理器期间发生的异常 - Python

python-3.x - 当我用可变参数初始化一个 dag 时,它会引发一个异常

postgresql - ansible postgres向数据库添加多个扩展(嵌套循环)

ubuntu - 无法访问 Oracle Cloud Always Free Compute http 端口

java - eclipse ubuntu 18.04安装java.lang.ClassNotFoundException :

python - 忽略少于三个词的项目

python - 从不同的类扩展 Python 类的功能

python - 当我尝试使用错误 'NoneType' 对象没有属性 'group' 的组时,Ansible regex_search 失败

带通配符的 Ansible 复制文件?

docker - 连接失败:连接已关闭(代码:1000)