Ansible Installation and Configuration on Redhat/CentOS 7
Step 3: INVENTORY
Use the default one /etc/ansible/hosts or create a custom host file. This is an inventory file where you have to maintain your remote host’s list. I will discuss more Ansible inventory in the next article.
The things in brackets are group names, which are used in classifying systems and deciding what systems you are controlling at what times and for what purpose.
Suggested Read: Quick Introduction to Static and Dynamic Inventories
My Inventory file (Static). The format for /etc/ansible/hosts is an INI format and looks like this:
Step 4: Ansible Ad-Hoc COMMANDS:
Introduction To Ad-Hoc Commands Examples of basic commands. An ad-hoc command is something that you might type in to do something really quick, but don’t want to save for later.
This is a good place to start to understand the basics of what Ansible can do prior to learning the playbooks language
– ad-hoc commands can also be used to do quick things that you might not necessarily want to write a full playbook for. Basically, the true power of Ansible is playing with playbooks. I will discuss playbook in the coming articles.
Run your first Ansible Ad-Hoc command to check ping response from remote hosts. The following examples show how to use /usr/bin/ansible for running ad hoc tasks
[ansadm@ansmaster ~]$ ansible -i /etc/ansible/hosts -m ping all
An Another command to know uptime for your all remote hosts from the Ansible inventory.
[ansadm@ansmaster ~]$ ansible all -i /etc/ansible/hosts -m command -a "uptime"
Step 5: Ansible MODULES
Ansible provides no. of modules that can be executed directly on remote hosts or through playbooks. Modules (also referred to as “task plugins” or “library plugins”) are the ones that do the actual work in ansible, they are what gets executed in each playbook task.
Confused ??? Let’s check all available modules on the Ansible server. You can get your Modules list and the module Documentation by running the below commands. List all modules available with that particular Ansible version
# ansible-doc -l
Check information of particular module
# ansible-doc <module>
LIST ALL MODULES
[ansadm@ansmaster ~]$ ansible-doc -l
VIEW MODULE DOCUMENTATION
Syntax : ansible-doc <module_name>
The below command will show you the document about “shell module”. press “q” for quit from document page.
[ansadm@ansmaster ~]$ ansible-doc shell
Conclusion: This is all about Ansible basics. if you’re cleared about the basics, then you are ready to move the next level to play with some basic Ad-Hoc commands on the remote host. I will share more information about Ad-Hoc commands in the next articles. I hope this guide will help you to start your journey towards Automation with Ansible.