How do i get Ansible predefined variables

0 votes
I'm trying to get ansible pre definied variables but I dont know how to get it. A little help would be good. Thank you..
Jan 24, 2019 in Ansible by Ninja
1,328 views

1 answer to this question.

0 votes

There three types of variables

  • variables gathered from the facts which can be extracted using the following command:

ansible -m setup hostname

  • pre-defined variables, you can use this playbook for it
---
# vars.yml
# Shows the value of all variables/facts.
# Example:
#   ansible-playbook vars.yml -e 'hosts=localhost'
- hosts: localhost
  tasks:
    - fail: "You must specify a value for `hosts` variable - e.g.: ansible-playbook vars.yml -e 'hosts=localhost'"
      when: hosts is not defined

- hosts: "{{ hosts }}"
  tasks:
    - debug: var=vars
    - debug: var=hostvars[inventory_hostname]
  • Variables passed through command lines which will obviously be known to you.
answered Jan 24, 2019 by Parth

Related Questions In Ansible

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
5,606 views
0 votes
1 answer

How do I access environment variables in Ansible?

Yes @Nagray, you're right! You can access ...READ MORE

answered Jan 24, 2019 in Ansible by Tessie
8,097 views
0 votes
1 answer

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

Hey @Ninja, that is possible. What you ...READ MORE

answered Jan 24, 2019 in Ansible by Thomas
1,991 views
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,503 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
3,503 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
3,862 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