Ansible modules overview

Ansible Modules

*Ping Module
The first module we going to see is a ping module i.e. used to check connectivity across ansible nodes.
#ansible -m ping all
#m → stands for modules, command module is the default module.
#all → to denote all hosts from the ansible hosts file

*Setup Module
#ansible -m setup node1
#ansible -m setup all | grep nodename

*File Module
The file module is one of the most used modules in an Ansible. As the name suggests it is used to manage and maintain a file like setting file attributes, symbolic links, etc.

*create a file
command: ansible -m file -a "path=/tmp/testfile state=touch"
set permission
command: ansible -m file -a "path=/tmp/testfile mode=0644"
create a soft link
command: ansible -m file -a "src=/tmp/testfile dest=/tmp/testlink state=link"
-a → stands for arguments(as passed) for concerned modules.

*Command Module
Default ansible module that is used to run/execute system commands over the target nodes.
#ansible -m command -a “ls -lrth /tmp/testfile”
or
#ansible -a "ls -lrth /tmp/testfile"
#ansible -a "touch /tmp/demo.sh"
#ansible -a "uptime" all

*Copy module
Module for copying the file from the master to control nodes. Useful in case files need to be copied on many machines simultaneously.
#ansible -m copy -a “src=/home/ansible/java.config dest=/tmp” 
#ansible -m copy -a “src=/home/ansible/java.config dest=/tmp” 
#ansible -m copy -a “src=/home/ansible/java.config dest=/tmp” 

*Fetch module
#ansible -m fetch -a “src=/home/ansible/java.config dest=/tmp”
#ansible -m fetch -a “src=/home/ansible/java.config dest=/tmp”

*ACL Module
Module to manage ACL permissions on host machines.
#ansible -m acl -a 'name=/tmp/java.config entity=ansible permissions="rwx" etype=user state=present'

*Cron Module
As the name suggests a module i.e. used to schedule Cron job on remote hosts.
#ansible -m cron -a 'name=freemem minute=10 hour=00 job="cron.sh >> /tmp/cron.txt"'

Like above ansible provided tonnes of useful and extraordinary modules to simplify day-to-day tasks and make the life of Ops easier and simple.



Recent Comments

No comments

Leave a Comment