ansible on batch management services

1 ansible Introduction

1.1 ansible Batch Management Services Overview

(1) is a software-based automation tools python language development
(2) is SSH remote management services for remote host-based batch management
(3) parallel management, simple deployment, applications are simple and convenient

1.2 ansible meaning batch management services

(1) improve the efficiency of the work
(2) improve the accuracy
(3) reduce the cost of maintenance
(4) reduce repetitive work

1.3 ansible batch management services

(1) can be configured for batch system operations
(2) can achieve mass deployment of software services
(3) can be achieved batch file data distribution
(4) can be achieved batch information collection system

1.4 ansible Batch Management Features

(1) do not need to start the service management side program (NO Server)
(2) management client does not need to write the configuration file (/etc/ansible/ansible.cfg)
(3) controlled end without installing the software program (libselinux-python)
(4) controlled terminal does not need to start the service program (no agent = agentless)
(5) service program many operational management module (module)
(6) use scripts written to automate (playbook)

1.5 ansible batch management service architecture

(1) connecting plug (connectior plugins): connector for connecting to the managed host terminal
(2) the core module (core modules): connecting the host operation realized, it depends on the specific module to do specific things
(3) from definition module (custom modules): write according to their needs specific module
(4) plugin (plugins): complete module function supplements
(5) screenplay (playbooks): ansible configuration file, multiple tasks defined in the script, ansible performed automatically by
(6) the list of hosts (host inventory): host inventory configuration information, the operating range is defined ansible requires the host
(7) the most important point is ansible is modular, that all operations are dependent on the module
111_ Figure Wang .png

2 ansible service deployment

2.1 ansible installation

System, kernel version

[root@m01 ~]#cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core) 
[root@m01 ~]#uname -a
Linux m01 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Installation ansible

[root@m01 ~]yum repolist    # 查看是否有相应epel源,安装ansible需要epel源
[root@m01 ~]yum install -y ansible
[root@m01 ~]#rpm -qa ansible
ansible-2.8.1-1.el7.noarch  # ansible版本

2.1 ansible syntax

ansible host information management module name -m -a "operational actions" 
1563888396102-e011e809-7cc9-424a-b75f-73dd5f0bb771.png

2.2 ansible main configuration file

Official Information: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html
profile

[root@m01 ~]#rpm -ql ansible
/etc/ansible/ansible.cfg     --- ansible配置文件 
/etc/ansible/hosts           --- 主机清单文件,定义管理的主机信息
/etc/ansible/roles           --- 角色目录(更加规范使用ansible)

ansible profile

vi /etc/ansible/ansible.cfg
#ansible_become=True             --- 开启用户切换功能
#ansible_become_method=sudo      --- 使用什么方式切换用户权限 su / sudo
#ansible_become_user=root        --- 默认切换成什么用户
#ansible_become_ask_pass=false   --- 是否使用密码认证

2.3 ansible Host List Configuration

ansible_become Open User sudo or su function
ansible_become_method Select Get Permissions way su / sudo
ansible_become_user Designating switching to what a user operation
ansible_become_password Su or sudo password is set to achieve information

2.3.1 Method One: Write a remote host address information

[root@m01 ~]#vim /etc/ansible/hosts 
# 最后面添加IP地址
172.16.1.7
172.16.1.31
172.16.1.41

Command detecting
all IP addresses can all be replaced by

root@m01 ~]#ansible all -m command -a "hostname"
172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

172.16.1.31 | CHANGED | rc=0 >>
nfs01

IP addresses can also be separated by commas

[root@m01 ~]#ansible 172.16.1.31,172.16.1.41,172.16.1.7 -m command -a "hostname"
172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.31 | CHANGED | rc=0 >>
nfs01

172.16.1.41 | CHANGED | rc=0 >>
backup

2.3.2 Method Two: Writing built-in variable information services

编写服务内置变量信息

ansible_port=xxx      --- 指定远程服务端口号
ansible_password=xxx  --- 指定远程服务密码信息
ansible_user=xxx      --- 指定以什么用户远程连接主机
ansible_host=xxx      --- 指定远程主机地址信息和名称做映射,XXX=ip地址

命令检测:
在这里密码,端口都默认一样的

[root@m01 ~]#vim /etc/ansible/hosts
nfs01 ansible_host=172.16.1.31
172.16.1.41 ansible_user=root ansible_password=123456
172.16.1.7  ansible_user=root ansible_password=123456 ansible_port=22 

# 命令执行
[root@m01 ~]#ansible all -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

如果端口,密码不一样该怎么用

[root@m01 ~]#vim /etc/ansible/hosts
nfs01 ansible_host=172.16.1.31
172.16.1.41 ansible_user=root ansible_password=123456
172.16.1.7  ansible_user=root ansible_password=654321 ansible_port=52113

# 命令执行
[root@m01 ~]#ansible all -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

2.3.3 方法三:编写服务主机组信息

编写服务主机组信息

[root@m01 ~]#vi /etc/ansible/hosts
[ichn]
nfs01 ansible_host=172.16.1.31
172.16.1.41 ansible_user=root ansible_password=123456
[web]
172.16.1.7  ansible_user=root ansible_password=123456 ansible_port=22  

命令检测
主机组所有名称可以用 all 代替

[root@m01 ~]#ansible all -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

主机组所有名称之间可以用逗号隔开

[root@m01 ~]#ansible ichn,web -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

2.2.4 方法四:编写服务主机子组信息

编写服务主机子组信息
children:是固定的

[root@m01 ~]#vim /etc/ansible/hosts
[nfs:children]
nfs_server
nfs_client
[nfs_server]
nfs01 ansible_host=172.16.1.31
[nfs_client]
172.16.1.41 ansible_user=root ansible_password=123456
172.16.1.7  ansible_user=root ansible_password=12345 ansible_port=22

命令检测
所有主机组,子组都可以用 all 来代替

[root@m01 ~]#ansible all -m command -a "hostname"
172.16.1.41 | CHANGED | rc=0 >>
backup

172.16.1.7 | CHANGED | rc=0 >>
web01

nfs01 | CHANGED | rc=0 >>
nfs01

所有主机组,子组都可以用 nfs 来代替

[root@m01 ~]#ansible nfs -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

172.16.1.7 | CHANGED | rc=0 >>
web01

172.16.1.41 | CHANGED | rc=0 >>
backup

可以单独启动其中一个子组

[root@m01 ~]#ansible nfs_server -m command -a "hostname"
nfs01 | CHANGED | rc=0 >>
nfs01

2.2.5 方法五:编写配置主机清单变量信息

配置主机清单变量信息

[root@m01 ~]#vim /etc/ansible/hosts
[nfs:vars]
pass=123456
port=873
[nfs]
172.16.1.31
172.16.1.41

[nfs_client]
172.16.1.41
[nfs_client:vars]
ansible_user=root
ansible_password=123456

命令检测
所有主机清单变量都可以用 all 来代替

[root@m01 ~]#ansible all -m command -a "hostname"
172.16.1.31 | CHANGED | rc=0 >>
nfs01

172.16.1.41 | CHANGED | rc=0 >>
backup

可以用变量的主机组来代替

[root@m01 ~]#ansible nfs -m command -a "hostname"
172.16.1.31 | CHANGED | rc=0 >>
nfs01

172.16.1.41 | CHANGED | rc=0 >>
backup

2.4 ansible远程连接操作异常说明

(1)查看主机清单配置文件是否正确
(2)利用SSH命令直接连接,连接不上查看有没有公钥  密码正不正确  指定用户正不正确  防火墙是否阻止
(3)远程管理一直报错,只要老的ansible远程会话存在

[root@m01 /]#ps -ef|grep ssh
# SSH远程服务进程(实现客户端远程连接)
root       1211      1  0 09:49 ?        00:00:00 /usr/sbin/sshd -D
# SSH远程连接会话进程(维持连接会话)
root       2179   1211  0 15:16 ?        00:00:00 sshd: root@pts/1,pts/2

3 ansible服务模块应用方法

3.1 command模块(默认模块,不加模块会默认使用command)

command – Execute commands on targets:对目标主机执行命令
Synopsis:模块详细说明
(1)模块多个参数要用空格分隔
(2)使用commad模块一些特殊符号信息不能使用,如果非要执行请使用shell模块
像变量$HOME和"<",">","|",";"和"&"将不起作用
Parameters:模块的参数

chdir 在运行命令之前,先切换指定目录(远程主机)
creates 在执行命令前,判断远程主机指定文件是否存在,如果存在,命令不执行
removes 在执行命令前,判断远程主机指定文件是否存在,如果存在,命令继续执行
free_form 在使用这个模块是, -a后面必须输入一个合法linux命令

参数演示
chdir:在运行命令之前,先切换指定目录(远程主机)

[root@m01 ~]#ansible 172.16.1.41 -m command -a "pwd"
172.16.1.41 | CHANGED | rc=0 >>
/root

[root@m01 ~]#ansible 172.16.1.41 -m command -a "chdir=/tmp pwd"
172.16.1.41 | CHANGED | rc=0 >>
/tmp

creates:在执行命令前,判断远程主机指定文件是否存在,如果存在,命令不执行

[root@m01 ansible]# ansible 172.16.1.41 -m command -a "creates=/etc/rsyncd.conf touch /etc/rsyncd.conf"
172.16.1.41 | SUCCESS | rc=0 >>
skipped, since /etc/rsyncd.conf exists      # 文件已存在,不会执行后续命令
    
[root@m01 ~]#ansible 172.16.1.41 -m command -a "creates=/tmp/test.txt touch /tmp/test.txt"
 [WARNING]: Consider using the file module with state=touch rather than running 'touch'.  If you need
to use command because file is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.

172.16.1.41 | CHANGED | rc=0 >>
# 文件没有,执行后续命令创建文件
[root@backup tmp]#ll 
total 2
-rw-r--r-- 1 root root   0 Jul 24 09:52 test.txt

3.2 shell模块(万能模块 )

shell – Execute shell commands on targets:在远程目录主机执行命令
Parameters:模块的参数 和command参数一样

chdir 在运行命令之前,先切换指定目录(远程主机)
creates 在执行命令前,判断远程主机指定文件是否存在,如果存在,命令不执行
removes 在执行命令前,判断远程主机指定文件是否存在,如果存在,命令继续执行
free_form 在使用这个模块是, -a后面必须输入一个合法linux命令

参数演示
shell识别 > 

[root@m01 ~]#ansible 172.16.1.41 -m shell -a "echo 123456 >/tmp/test.txt"
172.16.1.41 | CHANGED | rc=0 >>

[root@backup tmp]#cat test.txt
123456

3.3 script模块(脚本模块)

Runs a local script on a remote node after transferring it:远程批量执行本地脚本信息
shell模块远程执行脚本
第一步:编写一个脚本

[root@m01 scripts]#vim yum.sh
#!/bin/bash
yum install -y htop 

第二步:远程传输脚本

[root@m01 scripts]#ansible 172.16.1.41 -m copy -a "src=/server/scripts/yum.sh dest=/server/scripts"

第三步:批量执行脚本文件

[root@m01 scripts]#ansible 172.16.1.41 -m shell -a "sh /server/scripts/yum.sh"

script 远程执行脚本
第一步:编写脚本

[root@m01 scripts]#vim yum.sh
#!/bin/bash
yum install -y htop 

第二步:远程执行脚本

[root@m01 scripts]#ansible 172.16.1.41 -m script -a "/server/scripts/yum.sh"
# scripy模块可以省略sh

相比shell模块来讲,script不用将脚本传输到远程主机,脚本本身不用进行授权,即可利用script模块执行,不需要使用sh,更加简洁,高效。

3.4 copy模块 把本地文件推送到远程主机

copy:可以将本地数据批量拷贝到远程主机,可以将远程主机数据进行移动操作(并不是拉取)

src  指定本地要推送的源数据信息
dest 指定保存数据目录路径信息
mode 数据推送后修改数据权限
owner 修改数据推送后的所属用户信息
group 修改数据推送后的所属组信息
remote_src 指定源为远程主机路径信息
backup 将数据进行备份
content 在指定远程主机生成有数据的文件,指定文件内容
directory_mode 递归设定目录的权限,默认为系统默认权限
forces 如果目标主机包含该文件,但内容不同,如果设置为yes,则强制覆盖。
如果为no,则只有当目标主机的目标位置不存在该文件时,才复制。默认为yes。
others 所有的file模块里的选项都可以在这里使用

使用copy 模块,将/ichn/test.txt文件传输到各个服务器,权限修改为666 属主属组为ichn

[root@m01 ichn]#ansible all -m copy -a "src=/ichn/test.txt dest=/backup mode=666 owner=ichn group=ichn"

检查结果

[root@m01 ichn]#ansible all -m shell -a "ls -l /backup/test.txt"
172.16.1.41 | CHANGED | rc=0 >>
-rw-rw-rw- 1 ichn ichn 0 Jul 20 14:48 /backup/test.txt

172.16.1.31 | CHANGED | rc=0 >>
-rw-rw-rw- 1 ichn ichn 0 Jul 24 11:05 /backup/test.txt

ansible all -m copy -a "src=/ichn/ =/backup mode=666 owner=ichn group=ichn"
ansible all -m copy -a "src=/ichn dest=/backup mode=666 owner=ichn group=ichn"
说明: 复制目录是遵循rsync复制目录原理 目录后面有/ 和 没有/有区别
实现数据备份

ansible nfs -m copy -a "src=/ichn/ichn.txt dest=/backup backup=yes"

批量备份:

ansible nfs -m copy -a "src=/backup/ichn.txt dest=/backup/ichn.txt.bak remote_src=yes"

批量还原:

ansible nfs -m copy -a "src=/backup/ichn.txt.bak dest=/backup/ichn.txt remote_src=yes"

生成一个有数据的文件

ansible nfs_client -m copy -a "content="ichn123" dest=/etc/rsync.password mode=600"

3.5 fetch模块 拉取数据操作

参数:

dest 将远程主机拉取过来的文件保存在本地的路径信息
src 指定从远程主机要拉取的文件信息,只能拉取文件
flat 默认设置为no,如果设置为yes,将不显示172.16.1.41/etc/信息

参数演示:dest,src

[root@m01 tmp]#ansible 172.16.1.41 -m fetch -a "src=/etc/hosts dest=/tmp"

[root@m01 tmp]#ll
total 0
drwxr-xr-x 3 root root 17 Jul 24 21:27 172.16.1.41
drwx------ 2 root root  6 Jul 23 08:20 vmware-root

flat=yes

[root@m01 tmp]#ansible 172.16.1.41 -m fetch -a "src=/etc/hosts dest=/tmp/ flat=yes"

[root@m01 tmp]#ls
hosts  vmware-root

3.6 file模块 修改远程主机数据属性,创建和删除远程主机数据信息

参数:

path 指定远程主机上已有的一个文件数据
mode 修改数据权限数值
owner 修改属主
group 修改属组
src 指定要创建软链接的文件信息
recurse recurse=yes 将目录及目录里文件的权限递归修改 recurse=no 不递归





state
state=directory 创建目录,可以递归创建目录
state=touch 创建文件:如果路径不存在将创建一个空文件
state=link 创建软链接
state=hard 创建硬链接
state=absent 删除数据
state=file 检查文件是否存在

参数演示:mode owner group

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/tmp/test.txt mode=666 owner=ichn group=ichn" 

[root@backup tmp]#ll -d test.txt 
-rw-rw-rw- 1 ichn ichn 7 Jul 24 10:07 test.txt

state=directory:创建目录

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/tmp/yang state=directory"

[root@backup tmp]#ll
total 8
drwxr-xr-x 2 root   root     6 Jul 24 21:52 yang

递归创建目录

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/tmp/yang/yang1/yang2 state=directory"

[root@backup tmp]#tree yang
yang
└── yang1
    └── yang2

2 directories, 0 files

state=touch:创建文件,如果路径不存在将创建一个空文件

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/tmp/ceshi.txt state=touch"

state=link:创建软链接

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "src=/tmp/test.txt  path=/backup/test_soft_link.txt state=link"

state=hard:创建硬链接

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "src=/tmp/test.txt  path=/backup/test_hard_link.txt state=hard" 

state=absent:删除数据操作

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/backup/test_hard_link.txt state=absent" 

state=file:检查文件是否存在

[root@m01 tmp]#ansible 172.16.1.41 -m file -a "path=/tmp/ceshi.txt state=file" 

recurse=yes:递归修改权限

[root@m01 ~]#ansible 172.16.1.41 -m file -a "path=/tmp/yang/ mode=700 owner=ichn group=ichn recurse=yes"

3.7 yum模块 批量安装软件模块

参数:

name  指定要安装的软件名称




state
state=installed

安装软件
state=present
state=latest 更新软件
state=removed

移除卸载软件
state=absent 

参数演示:absent installed removed

[root@m01 tmp]#ansible 172.16.1.41 -m yum -a "name=htop state=absent"    --- 卸载软件 
[root@m01 tmp]#ansible 172.16.1.41 -m yum -a "name=htop state=installed" --- 安装软件
[root@m01 tmp]#ansible 172.16.1.41 -m yum -a "name=htop state=removed"   --- 卸载软件

3.8 service模块 批量管理服务启动状态

参数

name 管理哪个服务名称



state
state=reloaded 平滑重启服务
state=restarted 重启服务
state=started 启动服务
state=stopped 停止服务


enabled
enabled=no 开机不运行
enabled=yes 开机自动运行

参数演示:restarted started stopped enabled=no enabled=yes

[root@m01 tmp]#ansible 172.16.1.41 -m service -a "name=crond state=stopped"     停止服务
[root@m01 tmp]#ansible 172.16.1.41 -m service -a "name=crond state=started"     启动服务
[root@m01 tmp]#ansible 172.16.1.41 -m service -a "name=crond state=restarted"   重启服务
[root@m01 tmp]#ansible 172.16.1.41 -m service -a "name=crond enabled=no"            开机不启动服务
[root@m01 tmp]#ansible 172.16.1.41 -m service -a "name=crond enabled=yes"           开机启动服务

3.9 corn模块 批量部署定时任务

参数:

minute  分 Minute when the job should run ( 0-59, , /2, etc )
hour    时 Hour when the job should run ( 0-23, , /2, etc )
day     日 Day of the month the job should run ( 1-31, , /2, etc )
month   月 Month of the year the job should run ( 1-12, , /2, etc )
weekday 周 Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
job      工作:要做的事情
name     定义定时任务的描述信息


disabled
disabled=no 取消注释
disabled=yes 添加注释


state
state=absent 删除定时任务
state=present 创建定时任务

要求: 每隔五分钟,进行时间同步

ansible 172.16.1.41 -m cron -a "minute=*/5 job='ntpdate ntp1.aliyun.com &>/dev/null'"

要求: 每周五,晚上10:30, 需要去大保健

ansible 172.16.1.41 -m cron -a "name='大保健' minute=30 hour=22 weekday=5 job='make shufu &>/dev/null'"
说明: 定时任务配置时.需要添加name注释信息,否则会出现反复创建相同定时任务

注释定时任务 删除定时任务 创建定时任务

ansible 172.16.1.41 -m cron -a "name='大保健03' state=absent"   --- 删除指定定时任务
ansible 172.16.1.41 -m cron -a "name='大保健02' job='make shufu &>/dev/null' disabled=yes"
ansible 172.16.1.41 -m cron -a "name='大保健02' job='make shufu &>/dev/null' disabled=no"

3.10 user模块 批量创建创建用户

参数

name 创建的用户名称
password 设置用户密码信息 必须设置为密文
create_home yes 表示创建家目录 no 不创建家目录
shell 指定用户登录方式  shell=/sbin/nologin
group 指定用户属于哪个组 主要组
groups 指定用户属于哪个组 附属组
uid 指定用户uid数值
state=absent 删除用户
remove=yes 当与state=absent连用的时候,彻底删除指定用户。
remove=no 不删除家目录

参数演示:name create_home=no shell=/sbin/nologin  group  groups uid state=absent

# 批量创建虚拟用户
ansible 172.16.1.41 -m user -a "name=alex create_home=no shell=/sbin/nologin"
# 指定用户所属组
ansible 172.16.1.41 -m user -a "name=alex group=ichn groups=oldgirl"
# 指定用户uid
ansible 172.16.1.41 -m user -a "name=alex uid=2000"
# 删除用户
ansible 172.16.1.41 -m user -a "name=alex state=absent"

彻底删除指定用户:state=absent remove=yes

[root@m01 ~]#ansible 172.16.1.41 -m user -a "name=alex group=alex state=absent remove=yes"

给用户设置密码

ansible 172.16.1.41 -m user -a 'name=oldbaby password="$6$oldgirl$kAUTXVC2z1agr1HlmpFe9abFhWKwJ1fNyg64F95U3rVumwQfqOuhV3YkyZU9.H79TChzIKn5epl5M18B199qV1"'

密码生成方式
方法一:明文加密,算法生成密文

ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha512', 'mysecretsalt') }}"
# mypassword    --- 明文密码信息
# sha512        --- 明文转换为密文加密方法
# mysecretsalt  --- 用什么做算法依据生成密文信息

实践演示

[root@m01 ~]#ansible all -i localhost, -m debug -a "msg={{ '123456' | password_hash('sha512', 'ichn123') }}"
localhost | SUCCESS => {
    "msg": "$6$ichn123$W3jkmkkVTr.9UStm4S50RT2uIEjB/4GEtaAeVCSZ..uWVN1YGxHvluss9JVfAPV0gSJoGn1qAfxGyttIsTjcz0"
}

方法二:centos7无法使用
mkpasswd --method=sha-512
方法三:利用python模块功能
直接安装

[root@m01 ~]#yum install -y python-pip

优化pip源

[root@m01 ~]#mkdir ~/.pip/
[root@m01 ~]#vim ~/.pip/pip.conf
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
    
[install]
trusted-host=mirrors.aliyun.com

python -c "from passlib.hash import sha512_crypt; import getpass; print(sha512_crypt.using(rounds=5000).hash(getpass.getpass()))"
[root@m01 ~]#pip install passlib    # 安装

3.11 mount 批量挂载模块

参数 参数说明
fstype 指定挂载文件类型 fstype=nfs
opts  设定挂载的参数选项信息opts=ro opts=rw
path  挂载点路径信息
src   要被挂载的存储设备(目录信息)




state 
state状态参数
state =unmounted 立即卸载,/etc/fstab文件中不会永久卸载
state=absent   立即卸载,/etc/fstab文件中永久卸载
state=present  只能实现开机自动挂载
state=mounted 将挂载信息添加到/etc/fstab文件,开机自动挂载
实现立即挂载

参数演示:src  path fstype=nfs state=mounted state=unmounted

mount -t nfs 172.16.1.31:/data  /mnt        # /mnt挂载到172.16.1.31:/data
# 立即挂载 并且添加在/etc/fstab文件
ansible 172.16.1.41 -m mount -a "src=172.16.1.31:/data path=/mnt fstype=nfs state=mounted"
# 立即卸载,/etc/fstab文件中不会永久卸载
ansible 172.16.1.41 -m mount -a "src=172.16.1.31:/data path=/mnt fstype=nfs state=unmounted"

3.12 模块参数 ansible颜色提示信息说明

What are the important parameters
(1) through other people Bowen
(2) Tell me what network site documentation, red font tag
(3) Tell me what network sites document, for example configuration parameters using frequency  
ansible help view method
(1) View ansible All modules: ansible -l-DOC
(2) View module ansible parameter information: ansible-doc -s cron (module may change)
(3) See ansible module Details: ansible-doc cron (module may change)   
ansible message color explanation

yellow Make changes to the remote host
green For information, to the remote host does not have to make changes
red Execute commands remotely wrong
purple Warning messages (recommended information)
blue Command execution process

Guess you like

Origin www.cnblogs.com/basa/p/11298916.html