Ansible Boot Camp 6— Variables
Ansible boot camp series
Environment Variables
In Ansible, environment variables are used to set the environment parameters for action on the remote host. Ansible allows you to work with environment variables in a variety of ways.
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. When you set a value with environment:
at the play or block level, it is available only to tasks within the play or block that are executed by the same user. For example:
- name: Install nginx
ansible.builtin.yum:
name: nginx
state: latest
environment:
http_proxy: http://proxy.example.com:8080
Note that the environment
keyword does not affect Ansible configuration settings, the environment for other users, or the execution of other plugins like lookups and filters. Also variables set with environment
keyword do not automatically become Ansible facts. In order to make it as Ansible facts, you must include an explicit gather_facts task in your playbook and set the environment
keyword on that task to turn these values into Ansible facts.
For example:
---
- name: test
hosts: localhost
environment:
test_version: 1.0.0
tasks:
…