相關模組

  1. parted 分割硬碟,parted 模組文件,fs_type: ext4 可以立即將分割區格式化為 ext4,不用再使用 filesystem 模組格式化分割區。
    ceuser@deyu:~/ansible_pb$ ansible-doc parted| grep ^EX -A36
    EXAMPLES:
    
    - name: Create a new ext4 primary partition
      community.general.parted:
        device: /dev/sdb
        number: 1
        state: present
        fs_type: ext4
    
    - name: Remove partition number 1
      community.general.parted:
        device: /dev/sdb
        number: 1
        state: absent
    
    - name: Create a new primary partition with a size of 1GiB
      community.general.parted:
        device: /dev/sdb
        number: 1
        state: present
        part_end: 1GiB
    
    - name: Create a new primary partition for LVM
      community.general.parted:
        device: /dev/sdb
        number: 2
        flags: [ lvm ]
        state: present
        part_start: 1GiB
    
    - name: Create a new primary partition with a size of 1GiB at disk's end
      community.general.parted:
        device: /dev/sdb
        number: 3
        state: present
        fs_type: ext3
        part_start: -1GiB
    
  2. filesystem 檔案系統管理,filesystem 模組文件。
    ceuser@deyu:~/ansible_pb$ ansible-doc filesystem | grep ^EX -A30
    EXAMPLES:
    
    - name: Create a ext2 filesystem on /dev/sdb1
      community.general.filesystem:
        fstype: ext2
        dev: /dev/sdb1
    
    - name: Create a ext4 filesystem on /dev/sdb1 and check disk blocks
      community.general.filesystem:
        fstype: ext4
        dev: /dev/sdb1
        opts: -cc
    
    - name: Blank filesystem signature on /dev/sdb1
      community.general.filesystem:
        dev: /dev/sdb1
        state: absent
    
    - name: Create a filesystem on top of a regular file
      community.general.filesystem:
        dev: /path/to/disk.img
        fstype: vfat
    
  3. 檔案系統掛載管理,mount 模組將掛載要求寫入開機自動掛載表 /etc/fstab 中,其中 state: mounted 指定寫入 /etc/fstab 後立即掛載。
    ceuser@deyu:~/ansible_pb$ ansible-doc mount | grep ^EX -A86
    EXAMPLES:
    
    # Before 2.3, option 'name' was used instead of 'path'
    - name: Mount DVD read-only
      ansible.posix.mount:
        path: /mnt/dvd
        src: /dev/sr0
        fstype: iso9660
        opts: ro,noauto
        state: present
    
    - name: Mount up device by label
      ansible.posix.mount:
        path: /srv/disk
        src: LABEL=SOME_LABEL
        fstype: ext4
        state: present
    
    - name: Mount up device by UUID
      ansible.posix.mount:
        path: /home
        src: UUID=b3e48f45-f933-4c8e-a700-22a159ec9077
        fstype: xfs
        opts: noatime
        state: present
    
    - name: Unmount a mounted volume
      ansible.posix.mount:
        path: /tmp/mnt-pnt
        state: unmounted
    
    - name: Remount a mounted volume
      ansible.posix.mount:
        path: /tmp/mnt-pnt
        state: remounted
    
    # The following will not save changes to fstab, and only be temporary until
    # a reboot, or until calling "state: unmounted" followed by "state: mounted"
    # on the same "path"
    - name: Remount a mounted volume and append exec to the existing options
      ansible.posix.mount:
        path: /tmp
        state: remounted
        opts: exec
    
    - name: Mount and bind a volume
      ansible.posix.mount:
        path: /system/new_volume/boot
        src: /boot
        opts: bind
        state: mounted
        fstype: none
    
    - name: Mount an NFS volume
      ansible.posix.mount:
        src: 192.168.1.100:/nfs/ssd/shared_data
        path: /mnt/shared_data
        opts: rw,sync,hard
        state: mounted
        fstype: nfs
    
    - name: Mount NFS volumes with noauto according to boot option
      ansible.posix.mount:
        src: 192.168.1.100:/nfs/ssd/shared_data
        path: /mnt/shared_data
        opts: rw,sync,hard
        boot: false
        state: mounted
        fstype: nfs
    
    - name: Mount ephemeral SMB volume
      ansible.posix.mount:
        src: //192.168.1.200/share
        path: /mnt/smb_share
        opts: "rw,vers=3,file_mode=0600,dir_mode=0700,dom={{ ad_domain }},username={{ ad_username }},password={{ ad_password }}"
        fstype: cifs
        state: ephemeral