check_mount.yml
- name: 检查挂载目录
hosts:
- host5
- host10
tasks:
- name: 检查挂载状态
shell: df -Th | grep -E '/nvme1|/nvme2|/mnt/hdd1' || echo "未挂载"
register: mount_status
- name: 显示挂载状态标题
debug:
msg: "挂载状态:"
- name: 显示每个挂载点状态
debug:
msg: "{{ item }}"
loop: "{{ mount_status.stdout_lines }}"
- name: 检查是否有未挂载的目录
fail:
msg: "警告:存在未挂载的目录"
when: "mount_status.stdout_lines | length == 0 or '未挂载' in mount_status.stdout"
- name: 检查特定目录是否挂载
fail:
msg: "警告:{{ item }} 未挂载"
when: "item not in mount_status.stdout"
loop:
- "/nvme1"
- "/nvme2"
- "/mnt/hdd1"