update readme

This commit is contained in:
2025-09-20 14:28:45 -07:00
parent a08d8c9153
commit 3432e8ac9f
15 changed files with 457 additions and 257 deletions

254
tasks/working_folder.yaml Normal file
View File

@ -0,0 +1,254 @@
---
# this is for prepping the working folder, including mounting the storage if present and requested
# this folder needs to exist regardless of if there's storage to mount
- name: Working Folder - check folder
file:
path: "{{ working_storage }}"
state: directory
mode: '0755'
owner: root
group: root
- name: Working Folder - Check for Storage
shell: "df"
register: df_check_output
- name: Working Folder - Set storage_unmounted
when: working_storage in df_check_output.stdout
set_fact:
storage_unmounted: false
- name: Storage Handler Block
when: storage_unmounted and mount_storge | bool
block:
# find the device, architecture dependent
# the arm64 is intended for the friendlyelec devices
# which only have one sd slot, but still be careful
- name: Storage Handler - Get Storage Device arm64
when: '"arm64" in cpu_architecture'
block:
- name: Storage Handler - get boot device
shell: "blkid | grep '\"boot\"' | cut -d: -f 1 | cut -d/ -f 3 | cut -dp -f 1"
register: boot_device_arm64
- debug:
msg: "Boot device: {{ boot_device_arm64.stdout_lines[0] }}"
# this will choose the first storage device that it finds that isn't the boot device
# be careful and don't run this on an inappropriate host
- name: Storage Handler - Get Storage Device amd64
when: '"amd64" in cpu_architecture'
block:
- name: Storage Handler - get boot UUID
shell: 'cat /etc/fstab | grep " / " | grep UUID | cut -d= -f2 | cut -d " " -f 1'
register: boot_uuid
- debug:
msg: "Boot device UUID: {{ boot_uuid.stdout_lines[0] }}"
- name: Storage Handler - get boot device
shell: "blkid | grep {{ boot_uuid.stdout_lines[0] }} | cut -d: -f 1 | cut -d/ -f 3 | cut -dp -f 1 | cut -b 1-3"
register: boot_device_amd64
- debug:
msg: "Boot device: {{ boot_device_amd64.stdout_lines[0] }}"
- name: set boot_device variable
set_fact:
boot_device: "{{ boot_device_arm64.stdout_lines[0] | default(boot_device_amd64.stdout_lines[0]) }}"
- name: Storage Handler - get storage device
shell: "lsblk -o NAME,SIZE --nodeps | grep -v -e loop -e {{ boot_device }} -e NAME | cut -d ' ' -f 1"
register: storage_device_output
- name: Storage Handler - set uuid variable
set_fact:
storage_device: "{{ storage_device_output.stdout_lines[0] }}"
- debug:
msg: "Storage Device Found: {{ storage_device }}"
- name: Storage Handler - check for volumes
block:
- name: Storage Handler - Check for volumes on storage device
shell: 'lsblk | grep {{ storage_device }} | grep -v disk || true'
register: volume_check
- name: Storage Handler - Set format_storage variable
when: not storage_device in volume_check.stdout
set_fact:
format_storage: true
- name: Storage Handler - Test if format
when: format_storage
debug:
msg: "Looks like it's clobberin' time: {{ storage_device }} will be wiped and prepped"
- name: Storage Handler - Test if no format
when: not format_storage | bool
debug:
msg:
- "Looks like there's at least one volume there, the storage is safe:"
- "{{ volume_check.stdout_lines }}"
# this little block will format the storage found above
# it will be skipped unless you do something about it
- name: Storage Handler - format storage
# when: false
when: format_storage | bool
block:
- name: Storage Handler - clear existing partition table
shell: 'sgdisk --zap-all "/dev/{{ storage_device }}"'
- name: Storage Handler - create new partition table
shell: 'sgdisk --new=0:0:0 "/dev/{{ storage_device }}"'
- name: Storage Handler - create new volume table
shell: 'sgdisk --typecode=1:8300 --change-name=1:"Linux filesystem" "/dev/{{ storage_device }}"'
- name: Storage Handler - find new volume
shell: 'blkid | grep {{ storage_device }} | cut -d: -f1'
register: new_sd_volume
- name: Storage Handler - format new volume
shell: 'mkfs.ext4 {{ new_sd_volume.stdout_lines[0] }}'
register: format_output
- name: Storage Handler - show format stdout
debug:
msg: "{{ format_output.stdout_lines }}"
- name: Storage Handler - find storage volume
block:
- name: Storage Handler - get storage uuid
shell: "blkid | grep {{ storage_device }} | awk '{for (i=1; i<=NF; i++) print $i}' | grep UUID | grep -v PART | cut -d '\"' -f 2"
register: storage_uuid_output
- name: Storage Handler - set uuid variable
set_fact:
storage_uuid: "{{ storage_uuid_output.stdout_lines[0] }}"
- name: Storage Handler - Generate fstab entry
set_fact:
fstab_line_storage: "UUID={{ storage_uuid }} {{ working_storage }} ext4 errors=remount-ro 0 1"
- debug:
msg:
- "UUID Found:"
- "{{ storage_uuid }}"
- "fstab entry:"
- "{{ fstab_line_storage }}"
- name: Storage Handler - mount storage
block:
- name: Storage Handler - add fstab entry
lineinfile:
path: "/etc/fstab"
search_string: "{{ storage_uuid }}"
line: "{{ fstab_line_storage }}"
- name: Storage Handler - daemon reload
systemd:
daemon_reload: yes
- name: Storage Handler - Mount it
shell: mount -a
- name: Storage Handler - check for new mount point
shell: "df -h | grep -e Size -e {{ working_storage }}"
register: storage_output
- debug:
msg:
- "Storage handler drive mount result:"
- "{{ storage_output.stdout_lines }}"
###############################################
# this shares out the working folder with samba
# and builds an apache index site
###############################################
- name: Working Folder - samba and index
block:
- name: Working Folder - Share with samba
block:
- name: Working Folder - Create smb config file
template:
src: vcr_rip.conf
dest: "/etc/samba/smb.conf.d/vcr_rip.conf"
mode: 0644
- name: Working Folder - Include config 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"
insertbefore: '[global]'
- name: Working Folder - restart smbd
service:
name: smbd
state: restarted
enabled: yes
- name: Working Folder - Apache Index
block:
# Clone and build apache-index
- name: Working Folder - 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: Working Folder - 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: Working Folder - apache-index - Build image
docker_image:
name: apache-index # Name of the Storage 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: Storage Handler - apache-index results
debug:
msg:
- "{{ build_index_output.changed }}"
- "{{ build_index_output.failed }}"
- "{{ build_index_output.image.RootFS.Layers }}"
# start local-index
- name: Working Folder - local-index - create folder
file:
path: "{{ streaming_working_folder }}/local-index"
state: directory
mode: '0755'
- name: Working Folder - local-index - Copy config
template:
src: docker-compose-local-index.yaml
dest: "{{ streaming_working_folder }}/local-index/docker-compose.yaml"
mode: 0644
- name: Working Folder - 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 docker compose output"
- "{{ local_index_output.stdout_lines }}"
- "{{ local_index_output.stderr_lines }}"
...