我是那些有幸擁有破解SSL的公司代理人的人之一!/s爲什麼Ansible不尊重我的系統代理設置?
我的環境中有http_proxy,https_proxy,HTTP_PROXY和HTTPS_PROXY都正確配置。我通過/etc/profile.d中的shell腳本來配置所有4個環境變量。
我正在嘗試使用Ansible從pip安裝軟件包。這是我的問題。
我可以登錄到系統,然後鍵入以下命令:
pip install --trusted-host pypi.python.org robotframework
...,它會工作。我試過在Ansible中使用command
和pip
模塊做同樣的事情。沒有快樂。
使用pip
模塊:
- name: install robotframework
pip: name=robotframework extra_args='--trusted-host pypi.python.org'
become: true
結果在此:
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/bin/pip install --trusted-host pypi.python.org robotframework", "failed": true, "
invocation": {"module_args": {"chdir": null, "editable": true, "executable": null, "extra_args": "--trusted-host pypi.python.org", "name": "
robotframework", "requirements": null, "state": "present", "umask": null, "use_mirrors": true, "version": null, "virtualenv": null, "virtual
env_command": "virtualenv", "virtualenv_python": null, "virtualenv_site_packages": false}, "module_name": "pip"}, "msg": "stdout: Collecting
robotframework\n\n:stderr: You are using pip version 7.1.0, however version 9.0.1 is available.\nYou should consider upgrading via the 'pip
install --upgrade pip' command.\n Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolEr
ror('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=3, connect=None, read=No
ne, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotfr
amework/\n Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.
', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=1, connect=None, read=None, redirect=None)) afte
r connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Re
try(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network i
s unreachable'))': /simple/robotframework/\n Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by '
ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=3, connect=Non
e, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simp
le/robotframework/\n Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connectio
n aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=1, connect=None, read=None, redirect=N
one)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Re
trying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101,
'Network is unreachable'))': /simple/robotframework/\n Could not find a version that satisfies the requirement robotframework (from version
s:)\nNo matching distribution found for robotframework\n"}
使用command
模塊:
- name: install robotframework
command: "pip install --trusted-host pypi.python.org robotframework"
become: true
結果在此:
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["pip", "install", "--trusted-host", "pypi.python.org", "robotframework"], "delta":
"0:03:16.916685", "end": "2016-11-10 13:26:12.486105", "failed": true, "invocation": {"module_args": {"_raw_params": "pip install --trusted-
host pypi.python.org robotframework", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": tru
e}, "module_name": "command"}, "rc": 1, "start": "2016-11-10 13:22:55.569420", "stderr": "You are using pip version 7.1.0, however version 9
.0.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.\n Retrying (Retry(total=4, connect=None, rea
d=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/rob
otframework/\n Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection abor
ted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=2, connect=None, read=None, redirect=None))
after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying
(Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Netwo
rk is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken
by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=4, connect
=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))':/
simple/robotframework/\n Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Conne
ction aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=2, connect=None, read=None, redire
ct=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(1
01, 'Network is unreachable'))': /simple/robotframework/\n Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connecti
on broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/robotframework/\n Could not find a versi
on that satisfies the requirement robotframework (from versions:)\nNo matching distribution found for robotframework", "stdout": "Collectin
g robotframework", "stdout_lines": ["Collecting robotframework"], "warnings": []}
我完全不知所措。我認爲這對root用戶來說可能是有趣的,直到我以root用戶身份登錄併成功在shell中運行pip命令。我知道我使用的是舊版本的pip(感謝EPEL),但是這不應該導致command
調用失敗。即使我嘗試像警告狀態一樣升級pip,我也會得到相同的結果。
只工作了冗餘指定的任務代理URL的事情:
- name: install robot framework
pip: name=robotframework extra_args='--trusted-host pypi.python.org'
environment:
http_proxy: http://proxy1.example.com:8080
https_proxy: http://proxy1.example.com:8080
HTTP_PROXY: http://proxy1.example.com:8080
HTTPS_PROXY: http://proxy1.example.com:8080
become: true
become_user: root
我爲什麼要這麼做?如果我以root身份登錄,我可以看到設置了環境變量。我也不需要在Ansible中設置它們。