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 in Ansible by Ninja
287 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 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 30 in Ansible by Mahir
457 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 in Ansible by Tessie
1,523 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
• 6,890 points
1,812 views
+13 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,380 points
264 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer