How do I access environment variables in Ansible?

0 votes
How do I access environment variables in Ansible? I know we can use the lookup plugin but I'm not sure how to.
Jan 24 in Ansible by Nagraj
798 views

1 answer to this question.

0 votes

Yes @Nagray, you're right! You can access the environment variables on the local server using the lookup plugin. It lets you access the system data and environment variables. 

Example: prints HOME env variable

- hosts: all
  tasks:
    - name: Printing the environment​ variable in Ansible
      debug:
        msg: "{{ lookup('env','HOME') }}"

output
------
"msg": "/Users/mdtutorials2"
answered Jan 24 by Tessie

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 6,890 points
777 views
0 votes
1 answer
0 votes
1 answer

How do i get Ansible predefined variables?

There three types of variables variables gathered from ...READ MORE

answered Jan 24 in Ansible by Parth
175 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
152 views
0 votes
1 answer
0 votes
1 answer

How do I get a list of all Ansible variables?

Ansible by default gathers facts about machines ...READ MORE

answered Jan 30 in Ansible by Mahir
269 views
0 votes
1 answer

How do I add ssh authorized keys in ansible playbook?

Hey @kailash use the authorized_key plugin that ...READ MORE

answered Feb 11 in Ansible by Kyra
128 views