In most ansible example, it is to set environment like setting http_proxy below, see http://docs.ansible.com/playbooks_environment.html
- hosts: all
tasks:
- apt: name=cobbler state=installed
environment:
http_proxy: http://proxy.example.com:8080
In my case, I need this http_proxy
in system shell, while I want to disable this in playbook, how can I achieve this ?
If I work in shell, I can use unset http_proxy
You can use the environment keyword at the play, block, or task level to set an environment variable for an action on a remote host. With this keyword, you can enable using a proxy for a task that does http requests, set the required environment variables for language-specific version managers, and more.
We can use the ansible_env and lookup function to retrieve the environment variables stored. - name: Ansible playbook to get linux environment variables. The above playbook retrieves all the environment variables inside the unix os. Now we need to retrieve the USER env variable.
win_environment module – Modify environment variables on windows hosts. This module is part of the ansible.
How can I set the PATH or any other environment variable for a task or entire play? Setting environment variables can be done with the environment keyword. It can be used at the task or other levels in the play.
You could temporarily disable the proxy for the host(s) or URL you wanted to talk to, e.g.
environment:
no_proxy: 192.168.1.2,www.google.com
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