Ansible Detailed Explanation (5) - Detailed Explanation of the Use of Other Ansible Modules

Today, I will continue to introduce Linux operation and maintenance related knowledge. The main content of this article is a detailed explanation of Ansible's command module.
In the above Ansible detailed explanation (4) - Ansible command module detailed explanation , we introduced Ansible's three major command modules - command, shell and script. Today, let's introduce other modules of Ansible.

1. Ansible copy module

Ansible's copy module is used to transfer files on Ansible devices that are controlled first. This module has five commonly used parameters, the src parameter specifies the file location on the Ansible device, the dest parameter specifies the transfer destination location, the onwer parameter specifies the owner of the transferred file, the group parameter specifies the group of the file, and the mode parameter specifies the file file permissions. The copy module is applied as follows:

ansible exp -m copy -a "src=/root/ dest=/root/ owner=root group=root mode=0644"

The execution result is as follows:
insert image description here

2. Ansible file module

Ansible's file module is mainly used to set the file properties of Ansible controlled clients. The file module has two common parameters, the path parameter is used to specify the file of the controlled client, and the mode parameter is used to specify the properties to be set. Ansible's file module is used as follows:

ansible exp -m file -a "path=/root/ansible.txt mode=0777"

The execution result of the above command is as follows:
insert image description here

3. Ansible stat module

Ansible's stat module is mainly used to obtain the file attribute information of the controlled client. This module mainly has the path parameter to specify the file of the controlled client. Ansible's stat module is used as follows:

ansible exp -m stat -a "path=/root/ansible.txt"

The execution result of this command is as follows:
insert image description here

4. Ansible get_url module

Ansible's get_url module is mainly used to implement the controlled client to download files from remote to local. This module has four common parameters, the url parameter is mainly used to specify the file to be downloaded remotely by the controlled client, the dest parameter is mainly used to specify the destination folder, the mode parameter specifies the file permissions after downloading, and the force parameter can be yes or no. If the force parameter is yes, it means that if the downloaded content is different from the content of the file in the original directory, the original file will be downloaded and replaced. If it is the same, the download will not be performed; if the force parameter is no, the same name in the directory will be ignored. Is the file the same, download the file only if the target doesn't exist. Before Ansible 0.6, this parameter defaulted to yes, and after Ansible 0.6, this parameter defaulted to no. In the production environment, generally choose yes for downloading small files.
The module is used as follows:

ansible exp -m get_url -a "url=http://nginx.org/download/nginx-1.4.7.tar.gz dest=/root/ mode=0644 force=yes"

The execution result of this command is as follows:
insert image description here

5. Ansible yum module

Ansible's YUM module is mainly used to control the client to install software in the way of YUM. This module has two common parameters, the name parameter specifies the name of the software to be installed by Ansible, and the state parameter can be latest, present, installed to indicate installation, removed and abstract Indicates uninstall.
Ansible's YUM module is used as follows:

ansible exp -m yum "name=tree state=installed"

The execution result of this command is as follows:
insert image description here

6. Ansible cron module

Ansible's cron module mainly controls the controlled client to add scheduled tasks. There are three common parameters in this parameter, name indicates the name of the scheduled task, minute parameter specifies the interval of the scheduled task, and job specifies the specific operation. Ansible's cron module is used as follows:

ansible exp -m cron -a "name='exp' minute='*/1' job='pwd'"

The execution result of this command is as follows:
insert image description here
After the execution of this command is completed, a scheduled task appears on the controlled client device, and the result is as follows:
insert image description here

Seven, Ansible service module

Ansible's service module is mainly used to control the service startup of the controlled host. This module has two common parameters, name and state. The name parameter specifies the name of the service to be managed, and the state parameter specifies the operation to be performed on the specified service, which can be started, stopped, restarted. , reloaded (smooth restart). The module usage looks like this:

ansible -m service -a "name=mysqld state=stopped"

The execution result of this command is as follows:
insert image description here
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/123464853