Ansible - AD HOC Commands

Ansible ad hoc commands can be used when we have to perform a task quickly one a node or a group of nodes. Tasks can be executed in a single line of command without worrying about the YAML syntax.

Ansible modules can be called in the command based on the task we have to perform. Below are few ad hoc command examples.

1$ ansible node -m ping

This command is used to find if the managed node is reachable from control machine. Here we have used ping module.

ping 1

1$ ansible node -m shell -a uptime

This command is used with shell module to find the up time of the node.

1$ ansible node -m file -a "dest=/tmp/managed_node mode=755 state=directory"

This can be used to create a folder in the node using file module.

1$ ansible node -m copy -a "src=/tmp/index.html dest=/tmp/managed_node/index.html"

This command can be used to copy file from control node to the node using copy module.

1$ ansible node -m yum -a "name=httpd state=present"

This can be used to install httpd server on node using yum module.

1$ ansible node -m service -a "name=httpd state=started"

This can be used to start httpd service using service module.

Similarly, ad hoc commands can be used with any module to perform the required task on a single node or a group of nodes.

To Read More

I Accidentally wiped the entire dat...

One of the tragic accident in my job turned out to be good learning for me in re...

List of Docker Container Commands y...

This article covers list of commands that you should know to manage docker conta...

Everything you need to know about d...

Docker volume is a persistent data storage mechanism to store the data in docker...