1, ansible-doc command: Get the module list, and module use format;
Ansible-doc-l: Get list
Ansible-doc-s module_name: Get usage information for the specified module
2. Ansible command format
Ansible
|
Indicates a controlled host, expressed in the form of a pattern or given directly IP , must be defined in the document beforehand; All Set All |
[-F Forks] |
Number of hosts per batch, default is 5 host batch |
[-M module_name] |
What module management operations, all operations need to be specified through the module |
[-A args] |
module-specific parameters; Args are generally in key=value format Note: The parameters of the command module are not in KV format, but are given directly to execute the command; |
Attention:
-ipath,--inventory=path: Indicates the path of the host inventory file used;
Common modules (module_name):
1) Command: Default module, can be omitted. To operate commands on a remote host
-A ' COMMAND '
Note: The parameters of the Comand module are not in the Key=value format, giving the command to execute directly
[Email protected] ~]# ansible all-m command-a ' ifconfig '
2) User:
-A ' name= state={present (create) |absent (delete)} force= (whether to force delete home directory) system= uid= shell= home= '
[Email protected] ~]# ansible all-m user-a ' name=ansible state=present '
3) Group:
-A ' name= state={present|absent} gid= system= (System Group) '
[Email protected] ~]# ansible all-m group-a ' Name=mygroup state=presentsystem=true '
4) Cron:
-A ' name= state= minute= hour= day= month= weekday= job= '
[Email protected] ~]# ansible all-m cron-a ' name= ' time ' state=presentminute= ' */5 ' job= '/usr/sbin/ntpdate 172.168.0. 1 &>/dev/null '
5) Ping:
No parameters
[[email protected] ~]# ansible all-m Ping
6) File: Document management
-A ' path= mode= owner= group= state={file|directory|link|hard|touch|absent} src=\ ' #\ ' "/p>
[Email protected] ~]# ansible all-m file-a ' path=/tmp/testdirstate=directory '
[Email protected] ~]# ansible all-m file-a ' path=/tmp/test.txt state=touchmod=600 owner=user1 '
7) Copy:
-A ' dest= (path on remote host) src=\ ' #\ ' "content= (direct content) owner= group= mode= '
[Email protected]]# ansible web-m copy-a ' SRC=/ETC/YUM.REPOS.D/ALIYUN.R Epodest=/etc/yum.repos.d/'
8) Template
-A ' dest= src=\ ' #\ ' "content= owner= group= mode= '
9) Yum:
-A ' name= conf_file= (indicates configuration file) state= {present|latest|absent} enablerepo= disablerepo= '
[Email protected] ~]# ansible all-m yum ' name=httpd state=present '
Service:
-A ' name= state={started|stopped|restarted} enabled= (boot automatically) runlevel= '
[Email protected] ~]# ansible all-m service-a ' name=httpd state=started '
One) Shell:
-A ' command ' run shell command
[Email protected] ~]# ansible all-m shell-a echo "123456789" |passwd--stdin user1 '
Script:
-A '/path/to/script ' run script
[Email protected] ~]# ansible all-m script-a '/tmp/a.sh '
This article is from "Linux OPS rookie" blog, please be sure to keep this source http://zhangchuang.blog.51cto.com/10884116/1793744
Ansible Application Commands