Files
vcr_capture/tasks/sd_handler.yaml

155 lines
4.2 KiB
YAML

---
# when ran, this will look for an SD card
# optionally format it, be careful with that, it WILL destroy things
# map it to working_storage
# can only run on arm64
# '"arm64" in cpu_architecture'
- name: Video Capture - Check for SD
shell: "df"
register: df_check_output
- name: Video Capture - Set sd_unmounted
when: working_storage in df_check_output.stdout
set_fact:
sd_unmounted: false
- name: Video Capture - Set arm_arch
when: '"arm64" in cpu_architecture'
set_fact:
arm_arch: true
format_sd: false
- name: SD Handler - Checks have passed
when: sd_unmounted and arm_arch | bool
block:
- name: SD Handler - Get SD Device
block:
- name: SD Handler - get boot device
shell: "blkid | grep '\"boot\"' | cut -d: -f 1 | cut -d/ -f 3 | cut -dp -f 1"
register: boot_device
- name: SD Handler - get sd card device
shell: "lsblk -o NAME,SIZE --nodeps | grep -v -e loop -e {{ boot_device.stdout_lines[0] }} -e NAME | cut -d ' ' -f 1"
register: sd_card_device
- name: SD Handler - format SD card
when: format_sd | bool
block:
- name: SD Handler - clear existing partition table
shell: 'sgdisk --zap-all "/dev/{{ sd_card_device.stdout_lines[0] }}"'
- name: SD Handler - create new partition table
shell: 'sgdisk --new=0:0:0 "/dev/{{ sd_card_device.stdout_lines[0] }}"'
- name: SD Handler - create new volume table
shell: 'sgdisk --typecode=1:8300 --change-name=1:"Linux filesystem" "/dev/{{ sd_card_device.stdout_lines[0] }}"'
- name: SD Handler - find new volume
shell: 'blkid | grep {{ sd_card_device.stdout_lines[0] }} | cut -d: -f1'
register: new_sd_volume
- name: SD Handler - format new volume
shell: 'mkfs.ext4 {{ new_sd_volume.stdout_lines[0] }}'
register: format_output
- name: SD Handler - show format stdout
debug:
msg: "{{ format_output.stdout_lines }}"
- name: SD Handler - find SD card volume
block:
- name: SD Handler - get sd card uuid
shell: "blkid | grep {{ sd_card_device.stdout_lines[0] }} | awk '{for (i=1; i<=NF; i++) print $i}' | grep UUID | grep -v PART | cut -d '\"' -f 2"
register: sd_card_uuid_output
- name: SD Handler - set uuid variable
set_fact:
sd_card_uuid: "{{ sd_card_uuid_output.stdout_lines[0] }}"
- debug:
msg: "UUID Found: {{ sd_card_uuid }}"
- name: SD Handler - mount sd card
block:
- name: SD Handler - check folder
file:
path: "{{ working_storage }}"
state: directory
mode: '0755'
owner: root
group: root
- name: SD Handler - Generate fstab entry
set_fact:
fstab_line_sd: "UUID={{ sd_card_uuid }} {{ working_storage }} ext4 errors=remount-ro 0 1"
- name: SD Handler - add fstab entry
lineinfile:
path: "/etc/fstab"
search_string: "{{ sd_card_uuid }}"
line: "{{ fstab_line_sd }}"
- debug:
msg: |
fstab entry:
{{ fstab_line_sd }}
- name: SD Handler - daemon reload
systemd:
daemon_reload: yes
- name: SD Handler - Mount it
shell: mount -a
- name: SD Handler - validate this
block:
- name: SD Handler - check for new mount point
shell: "df -h | grep -e Size -e {{ working_storage }}"
register: sd_test_output
- debug:
msg: "{{ sd_test_output.stdout_lines }}"
- name: SD Handler - Share with samba
block:
- name: SD Handler - Create config file
copy:
dest: "/etc/samba/smb.conf.d/vcr_rip.conf"
content: |
[vcr_rip]
path = {{ working_storage }}
writable = yes
read only = no
only guest = yes
public = yes
guest ok = yes
guest only = yes
guest account = nobody
browsable = yes
mode: 0644
- name: SD Handler - Include in smb.conf
lineinfile:
path: "/etc/smb.conf"
search_string: "/etc/smb/smb.conf.d/vcr_rip.conf"
line: "/etc/smb/smb.conf.d/vcr_rip.conf"
insertafter: 'map to guest'
- name: SD Handler - restart smbd
service:
name: smbd
state: restarted
enabled: yes
...