Ansible - Monter des volumes

Il existe plusieurs façon de monter un volume avec Ansible dans un playbook.
Base de création d’un playbook : https://n0tes.fr/2023/02/12/Ansible-Playbook/

Monter un volume

Monter un volume :

---
- name: Monter un volume
ansible.posix.mount:
path: /home/levolume
src: data:/vol/leVolume
fstype: rw,rsize=32768,wsize=32768
state: mounted

- 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

Ce qui suit n’enregistre pas les modifications apportées à /etc/fstab sauf en cas de redémarrage ou en précisant l’option state : mounted:

- 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

Documentation

https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html

> Partager <