mount模块主要用于分区挂载

参数 必填 默认值 注解
name yes 本地挂载路径,如/mnt/files
src yes 挂载的设备路径,支持网络路径
fstype yes 文件系统类型,如 ext2/3/4
opts no 挂载选项,参考 fstab
state no present 1.present # 挂载,并写入 fstab 2.mounted # 仅挂载 3.absent/unmounted # 取消挂载

Ansible技术问答:http://linux.xyz/topic/Ansible

示例:

# 分区挂载
- mount: name={{ item.name }} src=/dev/{{ item.src }} fstype=ext4 state=present opts=noatime
 with_items:
 - { name: "/data",src: "sdb1"}
 - { name: "/log", src: "sdb2"}

# nfs 挂载示例
- name: Mount Directory
 mount: name=/data src=172.20.99.32:/data/. fstype=nfs state=present
 opts="rw,bg,rsize=32768,wsize=32768,tcp,hard,intr,noacl,noatime,nodiratime"