Initial commit
This commit is contained in:
24
roles/extroot/tasks/check.yml
Normal file
24
roles/extroot/tasks/check.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
# Set extroot status to false
|
||||
# to prevent permanent configuration
|
||||
- name: Set default extroot status fact to false
|
||||
ansible.builtin.set_fact:
|
||||
extroot_configure: false
|
||||
|
||||
# Check current extroot status
|
||||
- name: Check current extroot status
|
||||
uci:
|
||||
command: "get"
|
||||
config: "fstab"
|
||||
section: "@mount[0].target"
|
||||
type: "mount"
|
||||
register: extroot_status
|
||||
failed_when: >
|
||||
extroot_status.result is undefined and
|
||||
'Entry not found' not in extroot_status.result
|
||||
|
||||
# Set extroot status fact
|
||||
- name: Set extroot status fact
|
||||
ansible.builtin.set_fact:
|
||||
extroot_configure: true
|
||||
when: extroot_device not in extroot_status.result
|
||||
68
roles/extroot/tasks/fstab.yml
Normal file
68
roles/extroot/tasks/fstab.yml
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
# Get rootfs block device name
|
||||
- name: Get rootfs block device name
|
||||
ansible.builtin.command:
|
||||
cmd: 'sed -n -e "/\s\/overlay\s.*$/s///p" /etc/mtab'
|
||||
register: rootfs_block_device_name
|
||||
changed_when: rootfs_block_device_name.rc != 0
|
||||
|
||||
# Set rootfs block device name fact
|
||||
- name: Set rootfs block device name fact
|
||||
ansible.builtin.set_fact:
|
||||
block_device_name: "{{ rootfs_block_device_name.stdout }}"
|
||||
|
||||
# Mount rootfs data to another directory
|
||||
- name: Mount rootfs data to another directory
|
||||
block:
|
||||
# Add new mount point for root
|
||||
- name: Add new mount point for root
|
||||
uci:
|
||||
command: "add"
|
||||
config: "fstab"
|
||||
section: "rwm"
|
||||
type: "mount"
|
||||
|
||||
# Configure new mount point for root
|
||||
- name: Configure new mount point for root
|
||||
uci:
|
||||
command: "set"
|
||||
config: "fstab"
|
||||
section: "rwm"
|
||||
type: "mount"
|
||||
value:
|
||||
device: "{{ block_device_name }}"
|
||||
target: "/rwm"
|
||||
|
||||
# Get external USB device UUID
|
||||
- name: Get external usb device uuid
|
||||
ansible.builtin.command:
|
||||
cmd: 'block info /dev/{{ extroot_device }}1 | grep -o -e "UUID=\S*"'
|
||||
register: external_usb_device_uuid
|
||||
changed_when: external_usb_device_uuid.rc != 0
|
||||
|
||||
# Set external usb device uuid fact
|
||||
- name: Set external usb device uuid fact
|
||||
ansible.builtin.set_fact:
|
||||
usb_device_uuid: '{{ external_usb_device_uuid.stdout | regex_search(''(?<=")(.*?)(?=")'') }}'
|
||||
|
||||
# Mount external USB as overlayfs
|
||||
- name: Mount external usb as overlayfs
|
||||
block:
|
||||
# Add overlay mount point
|
||||
- name: Add overlay mount point
|
||||
uci:
|
||||
command: "add"
|
||||
config: "fstab"
|
||||
section: "overlay"
|
||||
type: "mount"
|
||||
|
||||
# Configure overlay mount point
|
||||
- name: Configure overlay mount point
|
||||
uci:
|
||||
command: "set"
|
||||
config: "fstab"
|
||||
section: "overlay"
|
||||
type: "mount"
|
||||
value:
|
||||
uuid: "{{ usb_device_uuid }}"
|
||||
target: "/overlay"
|
||||
39
roles/extroot/tasks/main.yml
Normal file
39
roles/extroot/tasks/main.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
# Check extroot status
|
||||
- name: Check extroot status
|
||||
ansible.builtin.include_tasks: check.yml
|
||||
when: extroot_enabled
|
||||
|
||||
# Install required packages
|
||||
- name: Install required packages
|
||||
ansible.builtin.include_tasks: prepare.yml
|
||||
when: extroot_configure
|
||||
|
||||
# Configure exteral USB drive
|
||||
- name: Configure external usb
|
||||
ansible.builtin.include_tasks: usb.yml
|
||||
when: extroot_configure
|
||||
|
||||
# Configure fstab
|
||||
- name: Configure fstab
|
||||
ansible.builtin.include_tasks: fstab.yml
|
||||
when: extroot_configure
|
||||
|
||||
# Configure system
|
||||
- name: Configure system
|
||||
ansible.builtin.include_tasks: system.yml
|
||||
when: extroot_configure
|
||||
|
||||
# Apply changes and reboot device
|
||||
- name: Apply changes and reboot device
|
||||
when: extroot_configure
|
||||
block:
|
||||
# Commit changes
|
||||
- name: Commit changes
|
||||
uci:
|
||||
command: commit
|
||||
notify: ["Reboot device", "Wait for device to boot up"]
|
||||
|
||||
# Reboot device
|
||||
- name: Reboot device
|
||||
ansible.builtin.meta: flush_handlers
|
||||
13
roles/extroot/tasks/prepare.yml
Normal file
13
roles/extroot/tasks/prepare.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# Update opkg cache
|
||||
- name: Update opkg cache
|
||||
ansible.builtin.command:
|
||||
cmd: "opkg update"
|
||||
changed_when: false
|
||||
|
||||
# Install required packages
|
||||
- name: Install required packages
|
||||
opkg:
|
||||
name: "{{ item }}"
|
||||
state: "present"
|
||||
loop: "{{ extroot_pkgs }}"
|
||||
55
roles/extroot/tasks/system.yml
Normal file
55
roles/extroot/tasks/system.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
# Copy overlay partition content to external USB device
|
||||
- name: Copy overlay content to external usb device
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ item }}"
|
||||
uses_shell: true
|
||||
loop:
|
||||
[
|
||||
"mount /dev/{{ extroot_device }}1 /mnt",
|
||||
"tar -C /overlay -cvf - . | tar -C /mnt -xf -",
|
||||
"umount /mnt",
|
||||
]
|
||||
loop_control:
|
||||
label: "{{ item }}"
|
||||
|
||||
# Configure hotplug extras
|
||||
- name: Configure hotplug extras
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ item }}"
|
||||
chdir: "/tmp"
|
||||
loop:
|
||||
[
|
||||
'uclient-fetch -O hotplug-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/hotplug_extras?codeblock=0"',
|
||||
"chmod +x ./hotplug-extras.sh",
|
||||
./hotplug-extras.sh,
|
||||
]
|
||||
|
||||
# Configure opkg extras
|
||||
- name: Configure opkg extras
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ item }}"
|
||||
chdir: "/tmp"
|
||||
loop:
|
||||
[
|
||||
'uclient-fetch -O opkg-extras.sh "https://openwrt.org/_export/code/docs/guide-user/advanced/opkg_extras?codeblock=0"',
|
||||
"chmod +x ./opkg-extras.sh",
|
||||
./opkg-extras.sh,
|
||||
]
|
||||
|
||||
# Configure extroot auto restore
|
||||
- name: Configure extroot auto restore
|
||||
ansible.builtin.copy:
|
||||
src: "90-extroot-restore"
|
||||
dest: "/etc/uci-defaults/90-extroot-restore"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
|
||||
# Add auto restore to sysupgrade configuration
|
||||
- name: Add auto restore to sysupgrade.conf
|
||||
ansible.builtin.lineinfile:
|
||||
path: "/etc/sysupgrade.conf"
|
||||
line: "/etc/uci-defaults"
|
||||
insertafter: "EOF"
|
||||
state: "present"
|
||||
10
roles/extroot/tasks/usb.yml
Normal file
10
roles/extroot/tasks/usb.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
# Create new partition in external USB disk
|
||||
- name: Create partition in external usb device
|
||||
ansible.builtin.command:
|
||||
cmd: "parted -s /dev/{{ extroot_device }} -- mklabel gpt mkpart extroot 2048s -2048s"
|
||||
|
||||
# Format partition to EXT4 file system
|
||||
- name: Format partition to ext4 fs
|
||||
ansible.builtin.command:
|
||||
cmd: "mkfs.ext4 -FL extroot /dev/{{ extroot_device }}1"
|
||||
Reference in New Issue
Block a user