Skip to content

Instantly share code, notes, and snippets.

@alivx
Created November 28, 2021 09:54
Show Gist options
  • Save alivx/503fd919acf6b423fc617453a324416e to your computer and use it in GitHub Desktop.
Save alivx/503fd919acf6b423fc617453a324416e to your computer and use it in GitHub Desktop.
Disk mount and bind
interfaces:
- name: var
path: /var
fstype: ext4
size: 20
dev: "xvdb"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,relatime
uuid: 'UUID"
location: /system/var
- name: home
path: /home
fstype: ext4
size: 5
dev: "xvdj"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,noexec,relatime
uuid: 'UUID"
location: /system/home
- name: srv
path: /srv
fstype: ext4
size: 10
dev: "xvdc"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,relatime
uuid: 'UUID"
location: /system/srv
- name: log
path: /var/log
fstype: ext4
size: 10
dev: "xvdd"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,noexec,relatime
uuid: 'UUID"
location: /system/log
- name: vartemp
path: /var/tmp
fstype: ext4
size: 5
dev: "xvdf"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,relatime
uuid: 'UUID"
location: /system/vartmp
- name: logaudit
path: /var/log/audit
fstype: ext4
size: 5
dev: "xvdg"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,noexec,relatime
uuid: 'UUID"
location: /system/audit_log
- name: tmp
path: /tmp
fstype: ext4
size: 5
dev: "xvdh"
opts: defaults,nofail,comment=cloudconfig,rw,nosuid,nodev,relatime
uuid: 'UUID"
location: /system/tmp
# - name: swap
# path:
# fstype: ext4
# size: 5
# dev: "xvdi"
# opts:
# uuid: 'UUID"
# location: /system/swap
- hosts: golden
gather_facts: no
vars_files:
- "./config.yaml"
tasks:
- name: Create a {{item.name}} filesystem on /dev/{{item.dev}}
community.general.filesystem:
fstype: ext4
dev: /dev/{{item.dev}}
loop: "{{ interfaces }}"
tags:
- mkfs
- name: Creates directory
file:
path: "{{item.location}}"
state: directory
tags:
- dir
loop: "{{ interfaces }}"
- name: Mount up device by label
ansible.posix.mount:
path: "{{item.location}}"
src: "UUID={{item.uuid}}"
fstype: ext4
opts: "{{item.opts}}"
state: present
fstab: /root/script/fstab.mount
loop: "{{ interfaces }}"
tags:
- mount
- name: mount all disks
ansible.builtin.shell: mount -a
tags:
- mount
- name: Sync
ansible.builtin.shell: rsync -vrag --inplace {{item.path}} {{item.location}}
loop: "{{ interfaces }}"
tags:
- sync
- name: Mount and bind a volume
ansible.posix.mount:
path: "{{item.location}}"
src: "{{item.path}}"
opts: bind
state: mounted
fstype: none
fstab: /root/script/fstab.bind
loop: "{{ interfaces }}"
tags:
- bind
- name: Run expect to wait for a successful PXE boot via out-of-band CIMC
ansible.builtin.shell: |
echo 'tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0' > /root/script/fstab.tmp
cp /etc/fstab /etc/fstab.backup
cat /root/script/fstab.mount >> /etc/fstab
cat /root/script/fstab.bind >> /etc/fstab
cat /root/script/fstab.tmp >> /etc/fstab
tags:
- fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment