What does the Ansible module know?
I used ansible in the company for a while and shared the introduction about the use of the ansible module.
Ansible provides many modules by default. In Linux, we can run the ansible-doc-l command to check which modules are supported by ansible, you can use the ansible-doc-s Module name to view the parameters available for this module.
The following describes several common modules:
Copy Module
File Module
Cron Module
Group Module
User Module
Yum Module
Service Module
Script Module
Ping Module
Command Module
Raw Module
Get_url Module
Synchronize Module
Functions and usage of Ansible and Docker
Ansible batch build LAMP Environment
Ansible: a configuration management and IT automation tool
Install and deploy Ansible in Linux
Copy module:
Objective: To copy the. sh file under the master/root directory to a specified Node
Command: ansible 10.1.1.113-m copy-a 'src =/root/a. sh dest =/tmp /'
Execution result:
File module:
Purpose: To change the/tmp/t. sh permission on a specified node to 755, and the owner and group are root.
Command: ansible all-m file-a "dest =/tmp/t. sh mode = 755 owner = root group = root"
Execution result:
Cron module:
Purpose: To define a scheduled task on a specified node and update the task to the master node every 3 minutes.
Command: ansible all-m cron-a 'name = "custom job" minute = */3 hour = * day = * month = * weekday = * job = "/usr/sbin/ntpdate 172.16.254.139 "'
Execution result:
Group module:
Objective: to create a group named nolinux and gid 2014 on all nodes
Command: ansible all-m group-a 'Gid = 2014 name = nolinux'
Execution result:
User Module:
Purpose: To create a user with the username of nolinux and a group of users with the name of nolinux on a specified Node
Command: ansible 10.1.1.113-m user-a 'name = nolinux groups = nolinux state = present'
Run the following command:
Supplement: User deletion example
Yum module:
Objective: To install the lrzsz service on a specified Node
Command: ansible all-m yum-a "state = present name = httpd"
Execution result:
Service module:
Purpose: To start the puppet service on a specified node and enable it to start automatically
Command: ansible 10.1.1.113-m service-a 'name = puppet state = restarted enabled = yes'
Execution result: