作业:
给node1添加一块5G的硬盘
给node2添加一块2G的硬盘
node3不添加硬盘
写一个partition.yml的playbook,满足如下要求:
给所有的受控主机创建分区,创建2500M的分区,然后对分区进行格式化,格式化为xfs的文件系统。
如果不能满足创建2500M的分区,则显示错误消息为:disk size not enough,接着改为创建1000M。
如果没有/dev/sdb硬盘,则显示错误消息为:the device is not sdb
[student@ansible ansible]$ cat partition.yml
[student@ansible ansible]$ cat partition.yml
---
- name: parted
hosts: all
tasks:
- block:
- name: create 2500M
parted:
device: /dev/sda
number: 1
state: present
part_type: primary
part_start: 10MiB
part_end: 2510MiB
rescue:
- name: not enough 2500m
debug:
msg: disk size not enough
- name: create 1000m
parted:
device: /dev/sda
number: 1
part_type: primary
part_start: 10MiB
part_end: 1010MiB
state: present
always:
- name: format
filesystem:
fstype: xfs
dev: /dev/sda1
when: "ansible_devices.sda is defined"
- name: not defined
debug:
msg: the device is not
when: "ansible_devices.sda is defined"
[student@ansible ansible]$ ansible-playbook partition.yml
PLAY [parted] **************************************************************