Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set proxy only for a particular ansible task?

I want to set an environment proxy only for a particular ansible task like get_url module to download some application from internet. Other all tasks should run without any proxy. How do I achieve this task.

like image 256
rolz Avatar asked Nov 10 '16 18:11

rolz


2 Answers

You can define an environment variable for your play and set the proxy option from get_url.

---
- hosts: all

  environment:
    http_proxy: http://127.0.0.1:1234

    # You can also set it over https.
    https_proxy: http://127.0.0.1:1234

- name: Retrieve some repo
  get_url:
    url: https://repos.com/cool.repo
    dest: /etc/yum.repos.d/cool.repo
    use_proxy: yes   

From use_proxy in the documentation:

if [use_proxy is set to] no, it will not use a proxy, even if one is defined in an environment variable on the target hosts.

So, you'll be doing the opposite in the example above.

like image 137
Yahir Cano Avatar answered Nov 19 '22 20:11

Yahir Cano


You can set a proxy per task, like so:

get_url:
  url=http://remote.host.com/file
  dest=/tmp/file
environment:
  http_proxy: http://proxy.example.com:8080
like image 8
Zlemini Avatar answered Nov 19 '22 19:11

Zlemini