Now we have written a playbook or adhoc command for
ansible -m ping all
Playbook is
---
- name: just fun
hosts: all
tasks:
- name: ping host
ping:
- name: print host
debug:
var: inventory_host
Now executing this playbook will result as shown below
Now we can supply –limit as shown below
Ansible Variables in separate files
Rather than writing variable data in inventory, it is a best practice to write them separately in a file, for that we need to understand how to create files for group variables and host variables
Lets assume this inventory and create it in a file called as hosts
The convention is in the folder wherever you have inventory in the same folder create folder named "group_vars" and the file name will be group_vars/<groupname>.yaml. Similarly for host variable the file names will be host_vars/<hostname>.yaml