Adhoc Commands Ansible
Adhoc Commands Ansible
***********************************************************************************
********************************
prerequisites
from ansible server login as an ansible user as per class 4.From ansible user
execute below command
this above ping command should return with ping / pong green color.
***********************************************************************************
********************************
Using the shell module looks like this:
***********************************************************************************
****************************************************
File Transfer
The file module allows changing ownership and permissions on files. These same
options can be passed directly to the copy module as well:
The file module can also create directories, similar to mkdir -p:
***********************************************************************************
****************************************************
Managing Packages
There are modules available for yum and apt. Here are some examples with yum.
Ansible has modules for managing packages under many platforms. If there isn’t a
module for your package manager, you can install packages using the command module
or (better!) contribute a module for your package manager. Stop by the mailing list
for info/details.
***********************************************************************************
****************************************************
The ‘user’ module allows easy creation and manipulation of existing user accounts,
as well as removal of user accounts that may exist:
***********************************************************************************
****************************************************
Managing Services
***********************************************************************************
***************************************
***********************************************************************************
***************************************
ansible ad hoc command to check uptime
Which one to pick is not a big confusion if you know what are they and their
capabilities
Here are the commands you can use to get the uptime. All three commands would yield
you the same results.
***********************************************************************************
***************************************
***********************************************************************************
***************************************
# To Start
ansible multi -m service -a "name=httod state=started enabled=yes"
# To Stop
ansible multi -m service -a "name=httpd state=stop enabled=yes"
***********************************************************************************
***************************************
***********************************************************************************
***************************************
To know more about Ansible async and poll refer this article
Rebooting the host in the background is the best example for fire and forget or
async and poll.
In this example, we are going to see how to check the status of service using
ansible ad hoc command
The following ad hoc command with copy module copies the file from Src location on
the local control machine to the specified location on the remote server
You need to notice that there is no / at the end of src path. It is just
/var/tmp/test
If you put a slash at the end. It would copy only the contents of the directory
alone but not the directory.
***********************************************************************************
***************************************
***********************************************************************************
***************************************
***********************************************************************************
***************************************
ansible ad hoc command to stop, start, restart, reload service
Simple way to restart any service with Ansible ad hoc command is to use Shell
module with the actual service or systemctl command
You can also use Ansible’s built in systemd module otherwise like this.
***********************************************************************************
***************************************
To download a file from URL in ansible ad hoc. You can either invoke linux commands
like CURL or WGET but the preferred way is to use the get_url module of Ansible.
This is how you can use get_url module in Ansible ad hoc to download a file in
remote system
***********************************************************************************
***************************************