Ansible provides many modules by default for our use. In Linux, you can see which modules are supported by the current ansible through the ansible-doc-l command, and you can see which parameters of the module can be used by ansible-doc-s the module name.
Common modules:
! All examples match the target host with webserver.
1.ping
Ansible all-m Ping
! Detects if the machine can log on, the ping module does not need to transfer parameters
! Note: The ping module here does not call the system's ping command, but is similar to logging on to the remote machine and then echo out a message.
2.command
! You can execute arbitrary commands, but do not accept pipe commands and redirection symbols, and if you want to use them, you need to use a shell module.
Ansible all-m command-a "ls" #在所有匹配主机上执行ls命令
Playbook
-Name:test for command
Command:ls
3.copy
#复制一个文件到远程服务器
Ansible all-m copy-a "Src=/tmp/text.txt dest=/home/tmp/"
#将本地text. txt files are copied to all matching hosts under the/home/tmp/path.
Playbook
-Name:test for copy
Copy:src=/tmp/text.txt Dest=/home/tmp/force=yes
4.file
This module is not used in this build system, the official explanation is to set the file, folder or Fast chain properties, or delete files, quick links, folders.
Create a folder if the target does not exist
Ansible webservers-m file-a "Path=/tmp/tdir state=directory mode=0755"
Playbook
-Name:create A directory if it doesn ' t exist
-File:
Path:/etc/some_directory
State:directory
mode:0755
5.get_url
Download a file from the server to a directory specified by the remote host
Ansible webservers-m get_url-a "url= ' http://baidu.com dest=/tmp/ba.html"
Playbook
-Name:download foo.conf
Get_url:
Url:http://example.com/path/file.conf
Dest:/etc/foo.conf
mode:0440
6.yum
Ideal for batch installation of some dependent packages
Ansible webservers-m yum-a "name=httpd state=latest"
Ansible webservers-m yum-a "name=httpd state=absent"! Delete Package
Playbook
-Name:install The latest version of Apache
Yum
Name:httpd
State:latest
7.service
Controlling services on a remote server
Ansible webservers-m service-a "Name=nginx State=restart"
Playbook
-Name:restart Rmote Nginx
Service:name=nginx State=restart
8.setup
Collecting remote Server information
Ansible all-m Setup
In playbook, this task is performed by default and does not need to be listed.
---------------------
Ref: 69945516
Ansible Common Commands