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
958 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
3,759 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
6,321 views
0 votes
1 answer
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,320 points
5,228 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
1,595 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,898 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP