-
Overview
At this post we will reveal below ansible modules and get them on practice with examplescommand copy file user group service script
-
Ansible module - user
[root@shell-master ~]# ansible-doc -s user - name: Manage user accounts
Example: Create new user
Run below command to create user wayne02[root@shell-master ~]# ansible webservers -m user -a "name=wayne02 home=/home/wayne02 shell=/bin/bash"
After the command finished, switch to shell-node1, checking if the user created:
-
Ansible module - group
[root@shell-master ~]# ansible-doc -s group - name: Add or remove groups
Example: Add new group
Run below command to create new group testing-group[root@shell-master ~]# ansible webservers -m group -a "name=testing-group state=present"
Switch back to shell-node1, verify if the group been created
-
Ansible module - service
[root@shell-master ~]# ansible-doc -s service - name: Manage services
By follow the help documentation, you can use below command format to perform service management, like restart, stop etc.
ansible webservers -m service -a "name=servicename ......"
-
Ansible module - script
[root@shell-master ~]# ansible-doc -s script - name: Runs a local script on a remote node after transferring it
Example: Build a local script, then transfer it to remote server and execute it
On shell-master, build a script file named testing.sh with below content (The scripts will create 1 readme.txt under /tmp/, and also create 10 data files under /tmp/):#!/bin/bash
cd /tmp/
# create readme.txt under /tmp/ cat > readme.txt << _EOF_ This is a testing script We‘ll create 10 data files under /tmp/ _EOF_ touch data{0..9}.dataAfter create the shell script file, you need to change it‘s access mode, let it can be executed by using below command:
[root@shell-master ~]# chmod 755 testing.sh [root@shell-master ~]# ls -lh testing.sh -rwxr-xr-x. 1 root root 169 Aug 8 08:53 testing.sh
Alright, let‘s using Ansible to post this script to be execution on remote server. Running below command to invoke ansible script module:
[root@shell-master ~]# ansible webservers -m script -a "testing.sh"
Then switch back to shell-node1, let‘s verify if the readme.txt and data files been created or not:
- All good with Ansible common modules now, next let‘s research on Ansible playbook.
相关文章
- 12-18JSLink and Display Templates Part 2 – Changing how individual fields display
- 12-18清北学堂(2019 5 2上午) part 5
- 12-18剑指offer PART 2
- 12-18ansible常用模块-2
- 12-18清北学堂part2
- 12-18[SPOJ1812-LCS2]Longest Common Substring II
- 12-18纯干货:深度学习实现之空间变换网络-part2
- 12-18ansible jinjia2
- 12-18Access-Based Enumeration (ABE) Concepts (part 1 of 2) (转载)
- 12-18Introduction to Fabric.js. Part 2(介绍Fabric.js第二部分)