Ansible study notes 10-format disk

1. Environment

M10---ansible control terminal

s30---client (data disk sdb 4GB)

s40---client (data disk sdb 2GB)

Two, examples

1. Check the disk

[root@m10 ~]# ansible -i iplist all -m shell -a 'lsblk'
192.168.164.40 | CHANGED | rc=0 >>
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0    4G  0 disk /data1
sr0     11:0    1 1024M  0 rom
sdc      8:32   0    2G  0 disk
sda      8:0    0   40G  0 disk
├─sda2   8:2    0    2G  0 part
├─sda3   8:3    0 37.7G  0 part /
└─sda1   8:1    0  300M  0 part /boot
192.168.164.30 | CHANGED | rc=0 >>
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 37.7G  0 part /
sdb      8:16   0    2G  0 disk /data1
sr0     11:0    1 1024M  0 rom

2. Create a mount directory

ansible -i iplist all -m shell -a 'mkdir /data1'

3. Format the sdb of all clients as xfs

ansible -i iplist all -m filesystem -a "fstype=xfs dev=/dev/sdb force=yes"

Note: If there is data in the disk before mounting, the data will be formatted and disappear.

4. Mount the disk

ansible -i iplist all -m mount -a 'name=/data1 src=/dev/sdb fstype=xfs state=mounted opts=rw'

3. Expansion

1. Introduction to mount module

path:       挂载点
src:        挂载的文件
fstype:     挂载的硬盘类型 比如iso9660、ext4、xfs、nfs、
            cifs samba的共享文件系统
            ntfs windows磁盘文件系统 
opts:       传递给mount命令的参数
state:      present	    开机挂载,仅将挂载配置写入/etc/fstab并不会真的挂载
	        mounted  	挂载设备,并将配置写入/etc/fstab
	        unmounted	卸载设备,不会清除/etc/fstab写入的配置
	        absent		卸载设备,并清理/etc/fstab写入的配置

Reference: 22-Ansible common modules disk management modules parted, lvg, lvol, filesystem, mount_ansible disk management modules_qq_41417660's blog-CSDN blog

Guess you like

Origin blog.csdn.net/xoofly/article/details/130103054