get_url: Request failed: <urlopen error (101, 'Network is unreachable')

Hi All,

I tried to use get_url in playbook.yml to download Elasticsearch package => failed.
But it is OK for me to use wget to download the package.
What should I do to get get_url works in ansible playbook?

My env: ansible v1.7.2, running on CentOS release 5.8

[vagrant@machine2]$ ansible-playbook /vagrant/provisioning/playbook.yml --inventory-file=/tmp/ansible_hosts --extra-vars “is_windows=true” --connection=local

PLAY [Configure Instance(s)] **************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.33.110]

TASK: [install jdk 1.7] *******************************************************
ok: [192.168.33.110]

TASK: [Download Elasticsearch package] ****************************************

failed: [192.168.33.110] => {“dest”: “/root/elasticsearch-1.4.0.tar.gz”, “failed”: true, “response”: “Request failed: <urlopen error (101, ‘Network is unreachable’)>”, “state”: “absent”, “status_code”: -1, “url”: “http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.0.tar.gz”}
msg: Request failed

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/vagrant/playbook.retry

192.168.33.110 : ok=2 changed=0 unreachable=0 failed=1

[vagrant@machine2 etc]$

---------------- my ansible: playbook.yml -----------------------------------

  • name: Configure Instance(s)
    hosts: all
    sudo: yes
    gather_facts: true

tags:

  • config
  • configure

tasks:

  • name: install jdk 1.7
    yum: pkg=java-1.7.0-openjdk state=installed

  • name: Download Elasticsearch package
    get_url: url=http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.0.tar.gz dest=~/elasticsearch-1.4.0.tar.gz

------------------------------------------ wget works --------------

[vagrant@machine2 src]$ wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.0.tar.gz
–2014-11-19 21:29:49-- http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.0.tar.gz
Resolving corp-proxy.mhc… 152.159.215.21
Connecting to corp-proxy.mhc|152.159.215.21|:8080… connected.
Proxy request sent, awaiting response… 200 OK
Length: 27730896 (26M) [application/x-tar]
Saving to: `elasticsearch-1.4.0.tar.gz.1’

100%[======================================>] 27,730,896 5.71M/s in 5.5s

2014-11-19 21:29:54 (4.82 MB/s) - `elasticsearch-1.4.0.tar.gz.1’ saved [27730896/27730896]

[vagrant@machine2 src]$

Thanks in advance for your help.
Diana

Are you using an http proxy by chance?

export |grep -i proxy

If so, you’ll need to tell ansible to use it. Ansible won’t inherit environment variables by default. Check this link to learn about using proxies with Ansible if that is the case.

http://docs.ansible.com/playbooks_environment.html

  • James

Hi James,

Thanks for your answer that “Ansible won’t inherit environment variable by default”
And I will try to use ansible the ‘environment’ keyword to configure the http_proxy setting. Thanks a lot!

Diana