215 lines
6.6 KiB
YAML
215 lines
6.6 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 - samba and index
|
|
block:
|
|
|
|
- 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/samba/smb.conf"
|
|
search_string: "/etc/samba/smb.conf.d/vcr_rip.conf"
|
|
line: "include /etc/samba/smb.conf.d/vcr_rip.conf"
|
|
insertafter: '[global]'
|
|
|
|
- name: SD Handler - restart smbd
|
|
service:
|
|
name: smbd
|
|
state: restarted
|
|
enabled: yes
|
|
|
|
- name: SD Handler - Apache Index
|
|
block:
|
|
|
|
###############################################
|
|
# Clone and build apache-index
|
|
###############################################
|
|
|
|
- name: SD Handler - - apache-index - Ensure the destination directory exists
|
|
file:
|
|
path: /opt/cosmos/apache-index # Replace with your desired directory on the target machine
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: SD Handler - - apache-index - Clone the Git repository
|
|
git:
|
|
repo: 'https://gitea.matt-cloud.com/matt/apache-index.git' # Replace with your repository URL
|
|
dest: '/opt/cosmos/apache-index' # Replace with your desired directory on the target machine
|
|
version: 'main' # Replace with the branch, tag, or commit you want to clone
|
|
force: yes
|
|
|
|
- name: SD Handler - - apache-index - Build image
|
|
docker_image:
|
|
name: apache-index # Name of the SD Handler - image
|
|
source: build
|
|
build:
|
|
path: /opt/cosmos/apache-index # Path to the directory containing your Dockerfile
|
|
state: present
|
|
tag: latest
|
|
register: build_index_output
|
|
- name: SD Handler - - apache-index - Image changed
|
|
debug: msg="{{ build_index_output.changed }}"
|
|
- name: SD Handler - - apache-index - Image failed
|
|
debug: msg="{{ build_index_output.failed }}"
|
|
- name: SD Handler - - apache-index - Image layers
|
|
debug: msg="{{ build_index_output.image.RootFS.Layers }}"
|
|
|
|
###############################################
|
|
# Install local-index 00
|
|
###############################################
|
|
|
|
- name: SD Handler - - local-index - create folder
|
|
file:
|
|
path: "{{ streaming_working_folder }}/local-index"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: SD Handler - - local-index - Copy config
|
|
template:
|
|
src: docker-compose-local-index.yaml.j2
|
|
dest: "{{ streaming_working_folder }}/local-index/docker-compose.yaml"
|
|
mode: 0644
|
|
|
|
- name: SD Handler - - local-index - Start container at 172.17.0.1:8080
|
|
shell: "docker-compose -f {{ streaming_working_folder }}/local-index/docker-compose.yaml up -d"
|
|
register: local_index_output
|
|
- debug: |
|
|
msg="{{ local_index_output.stdout_lines }}"
|
|
msg="{{ local_index_output.stderr_lines }}"
|
|
... |