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
21 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,560 points
317 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
58 views
+13 votes
2 answers
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
113 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.