Ad-hoc Commands

General syntax of an ad-hoc command:

Command hostgroup module/options [arguments]
FunctionCommand
To check the connectivity of hosts#ansible <group> -m ping
To reboot hosts#ansible <group> -a “/bin/reboot”
To check the host system’s info#ansible<group> -m setup | less
To transfer files#ansible <group> -m copy -a “src=home/ansible dest=/tmo/home”
To create a new user#ansible<group> -m user -a “name=ansible password= <encrypted password>”
To delete a user#ansible<group> -m user -a “name=ansible state- absent”
To check if a package is installed and to update it#ansible<group> -m yum -a “name=httpd state=latest”
To check if a package is installed but not to update it#ansible<group> -m yum -a “name=httpd state=present”
To check if a package is of a specific version#ansible<group> -m yum -a “name=httpd-1.8  state=latest”
To check if a package is not installed#ansible <group> -m yum -a “name= httpd state= absent
To start a service#ansible<group> -m service -a “name= httpd state=”started”
To stop a service#ansible<group> -m service -a “name= httpd state=”stopped”
To restart a service#ansible<group> -m service -a “name= httpd state=”restarted”

The general syntax of an ad-hoc command:

Command hostgroup module/options [arguments]
FunctionCommand
To check the connectivity of hosts#ansible <group> -m ping
To reboot hosts#ansible <group> -a “/bin/reboot”
To check the host system’s info#ansible<group> -m setup | less
To transfer files#ansible <group> -m copy -a “src=home/ansible dest=/tmo/home”
To create a new user#ansible<group> -m user -a “name=ansible password= <encrypted password>”
To delete a user#ansible<group> -m user -a “name=ansible state- absent”
To check if a package is installed and to update it#ansible<group> -m yum -a “name=httpd state=latest”
To check if a package is installed but not to update it#ansible<group> -m yum -a “name=httpd state=present”
To check if a package is of a specific version#ansible<group> -m yum -a “name=httpd-1.8  state=latest”
To check if a package is not installed#ansible <group> -m yum -a “name= httpd state= absent
To start a service#ansible<group> -m service -a “name= httpd state=”started”
To stop a service#ansible<group> -m service -a “name= httpd state=”stopped”
To restart a service#ansible<group> -m service -a “name= httpd state=”restarted”
Comments