Ansible in a Minute · Ansible Core ·
Use environment to set remote environment variables
Short answer
Use the environment keyword on a task so the remote action runs with specific environment variables.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
install a package with http_proxy set on the remote host
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
- name: Install a package through an HTTP proxy
hosts: all
become: true
gather_facts: false
tasks:
- name: Install curl with an HTTP proxy
ansible.builtin.package:
name: curl
state: present
environment:
http_proxy: http://proxy.example.com:8080How it works
environment sets variables for the remote action. It applies at play, block, or task level for tasks run by that user. It does not change Ansible itself, lookups, or filters on the controller.
When to use it
- Routing package or HTTP downloads through a proxy
- Setting language-runtime variables for one task
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-16
Notes
You can pass a dictionary variable to environment. Values set with environment do not become facts unless you gather facts in a task that also sets environment.
Reference
- Setting the remote environment (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.