---
- name: 设置Nomad节点NFS挂载
  hosts: nomad_nodes
  become: yes
  vars:
    nfs_server: "snail"
    nfs_share: "/fs/1000/nfs/Fnsync"
    mount_point: "/mnt/fnsync"

  tasks:

    - name: 安装NFS客户端
      package:
        name: nfs-common
        state: present

    - name: 创建挂载目录
      file:
        path: "{{ mount_point }}"
        state: directory
        mode: '0755'

    - name: 临时挂载NFS共享
      mount:
        path: "{{ mount_point }}"
        src: "{{ nfs_server }}:{{ nfs_share }}"
        fstype: nfs4
        opts: "rw,relatime,vers=4.2"
        state: mounted

    - name: 配置开机自动挂载
      lineinfile:
        path: /etc/fstab
        line: "{{ nfs_server }}:{{ nfs_share }} {{ mount_point }} nfs4 rw,relatime,vers=4.2 0 0"
        state: present

    - name: 验证挂载
      command: df -h {{ mount_point }}
      register: mount_check

    - name: 显示挂载信息
      debug:
        var: mount_check.stdout_lines