установить привязки python через pip - PullRequest
0 голосов
/ 25 сентября 2019

Я пытаюсь установить привязки python через ansible:


- name: install mongodb python bindings via pip
  pip: name=pymongo version="{{mongodb_version}}"

версия: 3.2

Сообщение об ошибке:

    "stderr": "  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb224d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/\n  Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22c90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/\n  Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22e10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/\n  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22f90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/\n  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdacc150>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/\n  Could not find a version that satisfies the requirement pymongo==3.2 (from versions: )\nNo matching distribution found for pymongo==3.2\nYou are using pip version 8.1.2, however version 19.2.3 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.", 
    "stderr_lines": [
        "  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb224d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/", 
        "  Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22c90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/", 
        "  Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22e10>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/", 
        "  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdb22f90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/", 
        "  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f66cdacc150>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/pymongo/", 
        "  Could not find a version that satisfies the requirement pymongo==3.2 (from versions: )", 
        "No matching distribution found for pymongo==3.2", 

Я экспортировал прокси-переменные до этогоstep.

Я добавил прокси-код здесь, пожалуйста, посмотрите.


- name: Set http proxy variables in /etc/profile
  lineinfile:
    path: /etc/profile
    line: 'export http_proxy={{http_proxy}}'
  when: http_proxy is defined

- name: Set https proxy variables in /etc/profile
  lineinfile:
    path: /etc/profile
    line: 'export https_proxy={{https_proxy}}'
  when: https_proxy is defined

- name: Set http proxy variables in /etc/profile
  lineinfile:
    path: /etc/profile
    line: 'export HTTP_PROXY={{http_proxy}}'
  when: http_proxy is defined

- name: Set https proxy variables in /etc/profile
  lineinfile:
    path: /etc/profile
    line: 'export HTTPS_PROXY={{https_proxy}}'
  when: https_proxy is defined

- name: Source the bashrc file
  action: shell source /etc/profile

Если я запускаю команду оболочки вручную на серверах, /usr/bin/pip install pymongo===3.2, она работает нормально, но когда я делаюэто через ansible, это не удается

1 Ответ

1 голос
/ 27 сентября 2019

Способ, которым вы пытаетесь установить переменные среды, не является постоянным между Ansible задачами.Вы должны использовать директиву environment, либо на уровне задачи, либо на уровне игры.

Например (уровень задачи):

- name: install mongodb python bindings via pip
  pip: name=pymongo version="{{mongodb_version}}"
  environment:
    http_proxy: "{{ http_proxy }}"
    https_proxy: "{{ https_proxy }}"

Или (уровень игры):

- hosts: all
  environment:
    http_proxy: "{{ http_proxy }}"
    https_proxy: "{{ https_proxy }}"
...