Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

get_url (module_utils/web.py)

ANSIBLE VERSION

ansible 2.2.0.0

CONFIGURATION

[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

OS / ENVIRONMENT

Controller machine: Darwin Kernel Version 15.6.0

Controlled machine: 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux

SUMMARY

When using module get_url to download from a HTTP URL, it does not use the OS environment variable http_proxy.

STEPS TO REPRODUCE

- name: "Download something through os.environ['http_proxy']"
get_url:
url: "http://wtfismyip.com/json"
dest: "/tmp/myip1.json"
become: yes

- name: "Download something through explicitly set ansible environment"
get_url:
url: "http://wtfismyip.com/json"
dest: "/tmp/myip2.json"
become: yes
environment:
http_proxy: http://same.proxy.like.in.etc.environments:8080

EXPECTED RESULTS

Both tasks should have produced the same file, containing the content of the URL url.

ACTUAL RESULTS

Only the second approach worked, when explicitly setting the environment through Ansible.

Not a single request was made to the proxy on the first approach.

By using the shell commands env and echo $http_proxy I can verify that Ansible is running with the full environment, including http_proxy.

Comments

https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/urls.py#L675

https_proxy is actually being respected by the module_util urls.py which is imported into get_url, but only https (secure), and not http (plain). Maybe this is a useful pointer

Thank you for any ideas or pull requests!

Issue 2:
ISSUE TYPE

Bug Report

But maybe also a Feature Idea?

COMPONENT NAME

Core

ANSIBLE VERSION

ansible 2.1.0.0
config file = /home/ubuntu/xxx/ansible.cfg
configured module search path = ['/home/ubuntu/xxx/library/']

CONFIGURATION

Not relevant

OS / ENVIRONMENT

Ubuntu 14.04

Network access must go through an http proxy, configured as typical in /etc/environment, via HTTP_PROXY and HTTPS_PROXY environment vars.

SUMMARY

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.

A member on #ansible suggested http://docs.ansible.com/ansible/playbooks_environment.html. 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 ansible 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 shell module for everything).

STEPS TO REPRODUCE

N/a

EXPECTED RESULTS

Ansible requires no special setup for machines behind http proxies.

ACTUAL RESULTS

Ansible's support for such an environment is nonexistent and the few available workarounds require manually specializing playbooks for such a case.