【问题标题】:How to install ansible 2.9+ on ubuntu 18.04 and utilize python3?如何在 ubuntu 18.04 上安装 ansible 2.9+ 并使用 python3?
【发布时间】:2020-06-16 18:29:17
【问题描述】:

我正在尝试在 Ubuntu Bionic (18.04 LTS) 上安装 minimal 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。 有谁知道如何安装 ansible 2.9 而无需安装 python2 或 pip3?

【问题讨论】:

  • 先安装pip3真的有那么大问题吗? apt install python3-pip python3-setuptools python3-wheel --yes --quiet; pip3 install ansible 似乎是最小的努力,特别是考虑到 Ansible 2.9 是在 18.04 发布 1.5 年后发布的。
  • 好的,有一个问题:github.com/ansible/ansible/issues/57342
  • @00 这实际上是一个问题。安装 pip3 想要248 MB of additional disk space。更新了问题以显示 pip3 要求。

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


【解决方案1】:

我已经针对仿生重新编译了 ansible 的焦点版本(它使用 python3),并在my PPA 上发布了它。只需要minimal changes。您只能使用 package in question 而不是启用整个 PPA。你最终会得到 ansible 2.9.6。

【讨论】:

    【解决方案2】:

    正如issue 中提到的,目前建议 Ubuntu 用户使用 Debian 存储库。可以直接here下载,使用

    安装下载的deb
    sudo apt-get install ./ansible_x.y.z_all.deb
    

    这将在不安装 python2 的情况下安装 ansible。 我已经在 Ubuntu 19.10 上成功测试了这个。

    【讨论】:

      【解决方案3】:

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

      sudo apt install ansible

      ansible 随 Python 2.7.x 一起安装

      我卸载了所有东西并使用 pip 安装了 ansible。现在,当我执行 ansible --version 时,我得到了

      ansible 2.9.11 配置文件 = /etc/ansible/ansible.cfg 配置的模块搜索路径 = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] 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]

      【讨论】:

        【解决方案4】:

        我也遇到了同样的问题。在我的情况下,由于 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问这种问题

        【讨论】:

        • 这仍然会安装 python2。
        • @IkarPohorský $ sudo apt search ansible 的输出是什么
        • ansible/bionic 2.9.7-1ppa~bionic all 但我的问题都是关于安装ansible 无需安装不再开发的python2.7
        猜你喜欢
        • 1970-01-01
        • 2020-06-26
        • 2020-01-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 2020-10-23
        • 1970-01-01
        相关资源
        最近更新 更多