# main.yaml
---
- hosts: local
vars:
disks:
- disk: /dev/sdb
number: 1
start: 0%
end: 50%
fstype: xfs
mount: /data1
tasks:
- include_tasks: tasks.yaml
with_items: "{{ disks }}"
# tasks.yaml
---
- name: tasks
block:
- name: 判断磁盘是否存在
shell: "test -b {{ item.disk }}"
register: result
ignore_errors: True
- name: 创建磁盘分区并挂载
block:
- name: 创建分区
parted:
device: "{{ item.disk }}"
number: "{{ item.number }}"
state: present
part_start: "{{ item.start }}"
part_end: "{{ item.end }}"
- name: 创建文件系统
filesystem:
fstype: "{{ item.fstype }}"
dev: "{{ item.disk }}{{ item.number }}"
- name: 挂载分区
mount:
path: "{{ item.mount }}"
src: "{{ item.disk }}{{ item.number }}"
fstype: "{{ item.fstype }}"
opts: noatime
state: mounted
when: result.rc == 0
ansible-platbook main.yaml
标签:tasks,name,number,fstype,disk,item,Ansible,磁盘分区
From: https://www.cnblogs.com/liy36/p/16907999.html