How do I get an ENV variable and store it into a local variable - Ansible

0 votes
Hey, This probably might be stupid but I'm just a beginner and need some help.

I'm trying to get the ENV variables and store them in a local variable and further use that variable in my playbook. Is that possible?
Jan 24 in Ansible by Ninja
73 views

1 answer to this question.

0 votes

Hey @Ninja, that is possible. What you could do is, use the lookup plugin to get the environment variables and assign this output to a variable, So now you can use this variable at other places in your playbook. 

- hosts: all
  vars:
    local_shell:  "{{ lookup('env','SHELL') }}"
  tasks:
    - debug:
        msg: "{{ local_shell }}"

output
------
"msg": "/bin/sh"
answered Jan 24 by Thomas

Related Questions In Ansible

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
1,653 views
0 votes
1 answer
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
239 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
206 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
373 views
0 votes
1 answer