<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<ul dir="auto">
<li>get_url (module_utils/web.py)</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
retry_files_enabled = False
display_skipped_hosts = False
hash_behaviour = &quot;merge&quot;
inventory = ./hosts
ansible_managed = This file is managed by Ansible.
  template: {file}
vault_password_file = ~/.vault_password
roles_path = ./roles/
[ssh_connection]
control_path=%(directory)s/%%h-%%p-%%r"><pre class="notranslate"><code class="notranslate">[defaults]
retry_files_enabled = False
display_skipped_hosts = False
hash_behaviour = "merge"
inventory = ./hosts
ansible_managed = This file is managed by Ansible.
  template: {file}
vault_password_file = ~/.vault_password
roles_path = ./roles/
[ssh_connection]
control_path=%(directory)s/%%h-%%p-%%r
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Controller machine: <code class="notranslate">Darwin Kernel Version 15.6.0</code><br>
Controlled machine: <code class="notranslate">3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux</code></p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">When using module get_url to download from a HTTP URL, it does <em>not</em> use the OS environment variable <code class="notranslate">http_proxy</code>.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: &quot;Download something through os.environ['http_proxy']&quot;
  get_url:
    url: &quot;http://wtfismyip.com/json&quot;
    dest: &quot;/tmp/myip1.json&quot;
  become: yes

- name: &quot;Download something through explicitly set ansible environment&quot;
  get_url:
    url: &quot;http://wtfismyip.com/json&quot;
    dest: &quot;/tmp/myip2.json&quot;
  become: yes
  environment:
    http_proxy: http://same.proxy.like.in.etc.environments:8080"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>Download something through os.environ['http_proxy']<span class="pl-pds">"</span></span>
  <span class="pl-ent">get_url</span>:
    <span class="pl-ent">url</span>: <span class="pl-s"><span class="pl-pds">"</span>http://wtfismyip.com/json<span class="pl-pds">"</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>/tmp/myip1.json<span class="pl-pds">"</span></span>
  <span class="pl-ent">become</span>: <span class="pl-s">yes</span>

- <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>Download something through explicitly set ansible environment<span class="pl-pds">"</span></span>
  <span class="pl-ent">get_url</span>:
    <span class="pl-ent">url</span>: <span class="pl-s"><span class="pl-pds">"</span>http://wtfismyip.com/json<span class="pl-pds">"</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>/tmp/myip2.json<span class="pl-pds">"</span></span>
  <span class="pl-ent">become</span>: <span class="pl-s">yes</span>
  <span class="pl-ent">environment</span>:
    <span class="pl-ent">http_proxy</span>: <span class="pl-s">http://same.proxy.like.in.etc.environments:8080</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Both tasks should have produced the same file, containing the content of the URL <code class="notranslate">url</code>.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Only the second approach worked, when explicitly setting the environment through Ansible.<br>
Not a single request was made to the proxy on the first approach.</p>
<p dir="auto">By using the shell commands <code class="notranslate">env</code> and <code class="notranslate">echo $http_proxy</code> I can verify that Ansible is running with the full environment, including <code class="notranslate">http_proxy</code>.</p>
<h4 dir="auto">Comments</h4>
<p dir="auto"><a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py#L675">https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py#L675</a><br>
<code class="notranslate">https_proxy</code> is actually being respected by the module_util <code class="notranslate">urls.py</code> which is imported into <code class="notranslate">get_url</code>, but only http<strong>s</strong> (secure), and not http (plain). Maybe this is a useful pointer</p>
<p dir="auto">Thank you for any ideas or pull requests!</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<p dir="auto">But maybe also a Feature Idea?</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.0.0
  config file = /home/ubuntu/xxx/ansible.cfg
  configured module search path = ['/home/ubuntu/xxx/library/']"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /home/ubuntu/xxx/ansible.cfg
  configured module search path = ['/home/ubuntu/xxx/library/']
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Not relevant</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu 14.04</p>
<p dir="auto">Network access must go through an http proxy, configured as typical in /etc/environment, via HTTP_PROXY and HTTPS_PROXY environment vars.</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Various modules that require network access (such as apt_key) are difficult to use in an environment such as the above. Ansible invokes shells in non-interactive mode which I understand does not load /etc/environment.</p>
<p dir="auto">A member on #ansible suggested <a href="http://docs.ansible.com/ansible/playbooks_environment.html" rel="nofollow">http://docs.ansible.com/ansible/playbooks_environment.html</a>. But this solution is strikingly manual for an "IT Automation" tool as it requires modifying every single play. Playbooks found online or through Galaxy must be manually modified as well. Additionally, there is NO workaround for ad-hoc commands - the plain <code class="notranslate">ansible</code> command does not provide a method for setting environment vars manually, or picking up any present on the remote system (short of falling back to the <code class="notranslate">shell</code> module for everything).</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">N/a</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Ansible requires no special setup for machines behind http proxies.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Ansible's support for such an environment is nonexistent and the few available workarounds require manually specializing playbooks for such a case.</p>