ansible(15)--ansible的mount模块
1. mount模块
功能:管理被控端设备挂载;
主要参数如下:
参数 | 说明 |
---|---|
src | 本地或远程设备的路径 |
path | 设备挂载至本地的路径 |
fstype | 挂载的文件系统类型,xfs、nfs... |
opts | 挂载的参数,defaults、ro... |
state | 挂载的状态,absent、mounted、unmounted |
-
环境准备:将
ansible
作为nfs
服务端,192.168.20.22
、192.168.20.23
作为nfs
客户端挂载;[root@xuzhichao ~]# ansible localhost -m yum -a 'name=nfs-utils state=present' [root@xuzhichao ~]# ansible localhost -m file -a 'path=/data/nfs/ owner=nginx group=nginx state=directory' [root@xuzhichao ~]# ansible localhost -m copy -a 'dest=/etc/exports content="/data/nfs 192.168.20.0/24(rw,all_squash,anonuid=887,anongid=887)\n"' [root@xuzhichao ~]# ansible localhost -m service -a 'name=nfs-server state=started' [root@xuzhichao ~]# exportfs -arv exporting 192.168.20.0/24:/data/nfs
-
示例一:挂载
nfs
至本地的/opt
目录,并实现开机自动挂载:[root@xuzhichao ~]# ansible NginxWebs -m mount -a 'src=192.168.20.17:/data/nfs path=/opt fstype=nfs opts=defaults state=mounted' [root@nginx03 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on 192.168.20.17:/data/nfs 154057344 33280 154024064 1% /opt [root@nginx03 ~]# cat /etc/fstab 192.168.20.17:/data/nfs /opt nfs defaults 0 0
-
示例二:临时卸载
nfs
的挂载,但不清理/etc/fstab
:[root@xuzhichao ~]# ansible NginxWebs -m mount -a 'src=192.168.20.17:/data/nfs path=/opt fstype=nfs opts=defaults state=unmounted'
-
示例三:永久卸载
nfs
挂载,同时清理/etc/fstab
:[root@xuzhichao ~]# ansible NginxWebs -m mount -a 'src=192.168.20.17:/data/nfs path=/opt fstype=nfs opts=defaults state=absent'