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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With