Ad-hoc command modules and how to use it?
Ad-hoc commands will perform quick tasks and not save that certain command for a later stage. In the commands below “-a” indicates that the command is an ad-hoc command.
See the list of nodes from the master server.
#ansible ubnt –m command –a ls/
Create a demo file in node2 from the server.
#ansible cent –m raw –a ‘touch /tmp/demo.txt’
Install Java on node2 from the server.
# ansible cent –m raw -a ‘yum install –y java’ (or) #ansible cent -m yum -a ‘name=java state=latest’
#ansible cent -m service -a ‘name=httpd state=started/restarted’
Copy a file from ansible server to nodes.
#ansible all –m copy -a “src= ‘/root/devops.txt’ dest=’/tmp/devops.txt’”
Create a file.
#ansible all –m file -a “name=/opt/sample.txt state=touch”
Remove a file.
#ansible all –m file -a “name=/opt/sample.txt state=absent”
Create a directory.
#ansible all –m file -a “name=/opt/devops state=directory”
Venkata Narayana Yarava is an experienced Cloud DevOps Engineer with exposure to various technologies. He has a huge passion for automation technologies, specifically DevOps Tools, OpenStack, AWS, Linux, and open-source software.
If you enjoy our articles please support us and make a small contribution: Buy Us A Coffee