title: Why isn't Ansible respecting my system proxy settings?
body: <p>I'm one of those people fortunate enough to have a corporate proxy that breaks SSL! /s</p>
  
  <p>My environment has http_proxy, https_proxy, HTTP_PROXY, and HTTPS_PROXY all correctly configured. I do my configuration via a shell script in /etc/profile.d that sets all 4 environment variables for me.</p>
  
  <p>I'm trying to use Ansible to install packages from pip. Here's my problem. </p>
  
  <p>I can log in to the system and type the following command:</p>
  
  <pre><code>pip install --trusted-host pypi.python.org robotframework
  </code></pre>
  
  <p>... and it will work. I've tried doing the same thing from inside Ansible both using <code>command</code> and <code>pip</code> modules. No joy.</p>
  
  <p>Using the <code>pip</code> module:</p>
  
  <pre><code>- name: install robotframework
    pip: name=robotframework extra_args='--trusted-host pypi.python.org'
    become: true
  </code></pre>
  
  <p>Results in this:</p>
  
  <pre><code>fatal: [localhost]: FAILED! =&gt; {"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"}
  </code></pre>
  
  <p>Using the <code>command</code> module:</p>
  
  <pre><code>- name: install robotframework
    command: "pip install --trusted-host pypi.python.org robotframework"
    become: true
  </code></pre>
  
  <p>Results in this:</p>
  
  <pre><code>fatal: [localhost]: FAILED! =&gt; {"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": []}
  </code></pre>
  
  <p>I am totally at a loss. I thought it might have been something funny with the root user, until I logged in as the root user and successfully ran the pip command at the shell. I know I'm on an old version of pip (thank EPEL for that), but that shouldn't be causing the <code>command</code> invocation to fail. Even when I try upgrading pip like the warning states, I get the same result. </p>
  
  <p>The only thing that worked was redundantly specifying the proxy url in the task:</p>
  
  <pre><code>- 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
  </code></pre>
  
  <p>Why do I need to do this? If I log in as root I can see that the environment variables are set. I shouldn't need to set them in Ansible, too.</p>