Ansible Ad-hoc Commands

Ansible ad-hoc commands will do a quick task but do not want to save that command for later. In below commands “-a” indicates the ad-hoc command.
To see the list of nodes from the master ad-hoc commands.
#ansible ubnt –m command –a ls/
To create a demo file in node2 from the server using ad-hoc commands.
#ansible  cent –m  raw  –a ‘touch  /tmp/demo.txt’
To install Java in node2 from the server using ad-hoc commands.
# ansible cent –m  raw  -a  ‘yum install –y java’

#ansible cent  -m  yum  -a  ‘name=java  state=latest’
To start/manage services by using ad-hoc commands
#ansible  cent  -m  service  -a  ‘name=httpd   state=started/restarted’
To copy a file from ansible server to nodes by using ad-hoc commands.
#ansible all –m  copy  -a  “src= ‘/root/devops.txt’  dest=’/tmp/devops.txt’”
To create a file by using ad-hoc commands
#ansible all –m  file  -a “name=/opt/sample.txt  state=touch”
To remove a file by using ad-hoc commands
#ansible all –m  file  -a “name=/opt/sample.txt  state=absent”
To create a directory by using ad-hoc commands
#ansible all –m  file  -a “name=/opt/devops  state=directory”
Ref:
https://devopssource.blogspot.com/2018/11/ansible-ad-hoc-commands.html

Leave a Reply

Your email address will not be published. Required fields are marked *