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
587 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 30, 2019 in Ansible by Mahir
1,682 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
4,398 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,910 points
3,594 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
804 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
1,764 views