如何使用Ansible正确升级点子?

时间:2019-01-14 10:10:45

标签: python python-2.7 pip ansible ubuntu-16.04

目标与环境

我正在针对 Ubuntu 16.04 使用ansible。 最终目标是使用mongodb_user模块。 这需要pymongo,所以需要python-pip

我在做什么

- name: Package prerequisites for pymongo ansible module
  apt:
    force_apt_get: yes
    name: ['python-pip', 'python-setuptools']
    install_recommends: no
    state: present
  become: true
  tags:
    - mongo
  register: output

- name: Upgrade pip to latest vesion
  pip:
    name: pip
    extra_args: --upgrade
  register: output

- debug:
    var: output    

问题

这是实际输出;请注意:

  • 似乎pip忽略升级说明
  • /usr/bin/pip2二进制文件,当时我期望
    "output": {
        "changed": true, 
        "cmd": [
            "/usr/bin/pip2", 
            "install", 
            "--upgrade", 
            "pip"
        ], 
        "failed": false, 
        "name": [
            "pip"
        ], 
        "requirements": null, 
        "state": "present", 
        "stderr": "You are using pip version 8.1.1, however version 18.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.\n", 
        "stderr_lines": [
            "You are using pip version 8.1.1, however version 18.1 is available.", 
            "You should consider upgrading via the 'pip install --upgrade pip' command."
        ], 
        "stdout": "Collecting pip\n  Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl\nInstalling collected packages: pip\nSuccessfully installed pip-8.1.1\n", 
        "stdout_lines": [
            "Collecting pip", 
            "  Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl", 
            "Installing collected packages: pip", 
            "Successfully installed pip-8.1.1"
        ], 
        "version": null, 
        "virtualenv": null
    }

奇怪的是,我从命令行得到了

$ /usr/bin/pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

$ /home/mirko/.local/bin/pip -V
pip 18.1 from /home/mirko/.local/lib/python2.7/site-packages/pip (python 2.7)

尝试

在安装python-pip之后,我试图手动升级pip并得到了另一个奇怪的东西:pip不想卸载旧的pip ...

sudo pip install pip --upgrade
[sudo] password for mirko: 
The directory '/home/mirko/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/mirko/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 1.2MB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr

问题

与ansible和Ubuntu 16.04搭配使用pip的正确方法是什么?

必须/可以强迫Ansible使用“我的”点子吗?

必须/我可以卸载“错误的”点子吗?

创建此双版本问题是否做错了什么?

2 个答案:

答案 0 :(得分:1)

env :Ubuntu 18.04,Python 3.6.9,最初位于9.0.1

我最终做了以下事情:

    - name: pip self-update
      pip:
        name: pip
        state: latest

请参阅doc about pip module

在运行pip要求安装之前,我全部独立完成了 。安装过程中有很多失败,并且pip太旧了,以至于我想确保在我接近其他安装项目之前都要格外小心。

这使我的得分提高到20.0.2左右。

更大的上下文:我确实指定了virtualenv,并且还通过清单文件设置了ansible_python_interpreter="/usr/bin/python3"

        virtualenv: "/srv/venv"

您可能不需要做这些事情,重要的是要确保200%的点是合理的最新水平。

答案 1 :(得分:0)

实际上我使用ubuntu特有的pymongo软件包解决了

- name: Package prerequisites for pymongo ansible module
  apt:
    force_apt_get: yes
    name: ['python-pip', 'python-setuptools', 'python-virtualenv', 'python-pymongo']
    install_recommends: yes
    state: present
  become: true
  tags:
    - mongo