Saturday, April 11, 2020

Ansible: Adhoc Commands

Ad-hoc command modules and how to use it?

Ad-hoc Commands:
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’
Start/manage services.
#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”


<Ansible: SSH configuration                                                 Ansible: Ansible Playbooks>


No comments:

Post a Comment

Featured Post

Ansible Tool Introduction

                                                                                                                                    Next ...