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, 2019 in Ansible by Ninja
2,638 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, 2019 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
• 7,340 points
6,912 views
0 votes
1 answer
0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
4,179 views
0 votes
1 answer

How do i get Ansible predefined variables?

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

answered Jan 24, 2019 in Ansible by Parth
1,614 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,061 views
+2 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 31, 2019 in Ansible by Mahir
6,144 views
0 votes
1 answer

How do I add apt key by id from a keyserver? - Ansible

Hey @Altis, you can use the module ...READ MORE

answered Feb 11, 2019 in Ansible by Kyra
3,785 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP