Print multiple env variables using ansible playbook

0 votes
How do I get multiple environment variables using ansible playbook?

I need home, shell and user in my output.

Thank you
Jan 24, 2019 in Ansible by Tom
2,227 views

1 answer to this question.

0 votes

Hey @Tom, you can use the lookup plugin to print environment variables. To print multiple env variables, just modify your arguments a little, something like this:

- hosts: all
  gather_facts: False
  tasks:
    - name: Multiple environment​ variables in a single line ansible task
      debug:
        msg: "{{ lookup('env','USER','HOME','SHELL') }}"

output
------
"msg": "root,/Users/user,/bin/sh"
answered Jan 24, 2019 by Rick
This will it print the envs of local machine, not of the managed node.

Related Questions In Ansible

0 votes
1 answer

ansible playbook: using multiple variables in loops

Use an indexed hostname, and then define ...READ MORE

answered Jul 16, 2018 in Ansible by DareDev
• 6,890 points
12,878 views
0 votes
1 answer
0 votes
1 answer

How to add multiple lines in a file using Ansible playbook?

Hi@akhtar, You can update your file using lineinfile ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,140 points
2,816 views
0 votes
1 answer

How to copy multiple files to remote system using Ansible Playbook?

Hi@akhtar, You can use the copy module in ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,140 points
2,510 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,033 views
+2 votes
1 answer
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
2,179 views