init commit

This commit is contained in:
2025-06-23 09:39:45 -07:00
commit 415d1536fb
10 changed files with 333 additions and 0 deletions

105
tasks/lldp.yaml Normal file
View File

@ -0,0 +1,105 @@
---
# Install Packages
- name: prereqs - install apt packages
apt:
name: "{{ item }}"
state: present
loop: "{{ lldp_packages }}"
###############################################
# LLDP Python api
###############################################
- name: LLDP API
block:
# Create API Folder
- name: lldp - api - create api folder
file:
path: "{{ api_working_dir }}"
state: directory
mode: '0755'
# Copy API Code
- name: lldp - api - copy api code
copy:
src: lldp-api.py
dest: "{{ api_working_dir }}/app.py"
mode: 0644
# Create lldp-api python service
- name: lldp - api - create service file
vars:
exec_start: "python3 {{ api_working_dir }}/app.py"
svc_desc: "LLDP API"
working_dir: "{{ api_working_dir }}"
template:
src: service_template.j2
dest: /etc/systemd/system/lldp_api.service
mode: 0644
# enable and start lldp service
- name: lldp - Restart LLDP service
service:
name: lldpd
state: restarted
enabled: yes
# daemon reload
- name: lldp - api - daemon reload
systemd:
daemon_reload: yes
# Enable and start
- name: lldp - api - enable and start api
systemd:
name: lldp_api.service
state: started
enabled: yes
# Test
- name: lldp - api - test
shell: "curl -S 'http://127.0.0.1:5000/data'"
register: api_test
# Show test results
- name: lldp - api - show result
debug:
msg: "{{ api_test.stdout }}"
###############################################
# LLDP Project
###############################################
# Create working dir
- name: LLDP Project - Create Working Directory
file:
path: "{{ lldp_project_working_dir }}"
state: directory
owner: "{{ admin_username }}"
group: "{{ admin_username }}"
mode: '0755'
# Copy python code
- name: LLDP Project - copy app code
copy:
src: lldp-scan.py
dest: "{{ lldp_project_working_dir }}/app.py"
owner: "{{ admin_username }}"
group: "{{ admin_username }}"
mode: 0644
# Copy project file
- name: LLDP Project - copy project code
vars:
project_title: "LLDP Scanner"
working_dir: "{{ lldp_project_working_dir }}"
template:
src: project_template.j2
dest: "{{ lldp_project_working_dir }}/project.cfg"
owner: "{{ admin_username }}"
group: "{{ admin_username }}"
mode: 0644
...

37
tasks/main.yaml Normal file
View File

@ -0,0 +1,37 @@
---
- name: Check for pi user
shell: "getent passwd | grep pi"
register: pi_user_output
ignore_errors: true
- name: Set pi_user_exists
set_fact:
pi_user_exists: "{{ not pi_user_output.failed | bool }}"
- name: Create pi user
when: not pi_user_exists | bool
user:
name: "pi"
password: "{{ pi_default_password | password_hash('sha512') }}"
shell: /bin/bash
- name: Check for pi-top platform
shell: pi-top --help
register: pitop_output
ignore_errors: true
- name: Set deb_base
set_fact:
deb_base: true
when: pitop_output.failed
ignore_errors: true
- name: Onboard if base debian
include_tasks: onboard.yaml
when: deb_base
- name: Install the requested project
include_tasks: "{{ function }}.yaml"
...

28
tasks/onboard.yaml Normal file
View File

@ -0,0 +1,28 @@
---
# Install prereq new APT source
- name: prereqs - install apt packages
apt:
name: pi-top-os-apt-source
state: present
# update APT with new source
- name: Update APT
apt:
update_cache: yes
# Install pi-top platform
- name: Install Pi-Top Platform - Will take less than 10 minutes
apt:
name:
- pt-device-support
state: present
# Install postreq OS utilities needed for user projects
- name: postreqs - full OS install, will take 15 minutes or so
apt:
name: pt-os
state: present
...

15
tasks/purge-defaults.yaml Normal file
View File

@ -0,0 +1,15 @@
---
- name: Create the purge path
file:
path: "{{ archive_path }}"
state: directory
mode: '0755'
- name: Move default projects
shell: |
mv {{ project_path }}/{{ item }} {{ archive_path }}
ignore_errors: true
loop: "{{ default_projects }}"
...