Bootstrap FreeKB - Ansible - Getting Started with Variables
Ansible - Getting Started with Variables

Updated:   |  Ansible articles

In Ansible, there are three types of Special Variables.

A magic variable are variables that are built into Ansible. Following are the magic variables.

For example, let's say you have a playbook named version.yml and version.yml contains the following.

---
- hosts: localhost
  tasks:
  - debug:
      var: ansible_version
...

 

You can run the version.yml playbook using the ansible-playbook command.

ansible-playbook version.yml

 

Which should return something like this.

TASK [debug]
ok: [localhost] => {
    "ansible_version": {
        "full": "2.9.27", 
        "major": 2, 
        "minor": 9, 
        "revision": 27, 
        "string": "2.9.27"
    }
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


January 31 2022 by vergissmiNET
Sorry but this article is a complete mess. You start talking about magic variables and give a (completely different) fact as an example. And what has 'gather_facts' to do with magic vars? [ansible@ansible-control http]$ cat magiclocal.yml --- - name: test hosts: localhost gather_facts: False tasks: - debug: var: ansible_version [ansible@ansible-control http]$ ap magiclocal.yml PLAY [test] ********************************************************************************************* TASK [debug] ******************************************************************************************** ok: [localhost] => { "ansible_version": { "full": "2.9.27", "major": 2, "minor": 9, "revision": 27, "string": "2.9.27" } } PLAY RECAP ********************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

January 31 2022 by Jeremy (moderator)
Yeah, this article was confusing. I was way overdue to clean up this article. I got this article cleaned up so that it makes sense now.

Add a Comment


Please enter 8e5490 in the box below so that we can be sure you are a human.