From eb829c624c10ea41cae6bcf5f0e3010160f598d9 Mon Sep 17 00:00:00 2001 From: jerick Date: Fri, 30 Jan 2026 14:49:44 -0500 Subject: [PATCH] first commit --- Jenkinsfile | 95 +++++++++++++++++++++++++++++++ README.md | 22 +++++++ inventories/inventory.proxmox.yml | 25 ++++++++ playbooks/dockerPrune.yaml | 11 ++++ playbooks/dockerUpdate.yml | 57 +++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 Jenkinsfile create mode 100644 README.md create mode 100644 inventories/inventory.proxmox.yml create mode 100644 playbooks/dockerPrune.yaml create mode 100644 playbooks/dockerUpdate.yml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..9cabcc0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,95 @@ +pipeline { + agent any + + parameters { + choice( + name: 'PLAYBOOK', + choices: ['dockerUpdate.yml', 'dockerPrune.yaml'], + description: 'Select the playbook to run' + ) + string( + name: 'LIMIT', + defaultValue: '', + description: 'Limit to specific hosts or groups (e.g., "vms", "lxcs", "update_targets", or hostname) no.lan required' + ) + booleanParam( + name: 'DRY_RUN', + defaultValue: false, + description: 'Run in check mode (no changes made)' + ) + } + + environment { + PROXMOX_URL = 'https://192.168.0.166:8006' + PROXMOX_USER = 'dynamic-inventory@pve' + PROXMOX_TOKEN_ID = 'dynamic-inventory' + PROXMOX_TOKEN_SECRET = credentials('PROXMOX_TOKEN_SECRET') + ANSIBLE_HOST_KEY_CHECKING = 'False' + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Verify Inventory') { + steps { + sh ''' + echo "Testing dynamic inventory connection..." + ansible-inventory -i inventories/inventory.proxmox.yml --list | head -10 + ''' + } + } + + stage('Run Playbook') { + steps { + script { + def dockerPlaybooks = ['dockerUpdate.yml', 'dockerPrune.yaml'] + def isDockerPlaybook = params.PLAYBOOK in dockerPlaybooks + + // Build the limit flag + def limitValue = '' + if (isDockerPlaybook) { + // Docker playbooks always target 'docker' tagged hosts + // If user provides a limit, use intersection (docker AND limit) + limitValue = params.LIMIT ? "docker:&${params.LIMIT}" : 'docker' + } else { + limitValue = params.LIMIT ?: '' + } + + def limitFlag = limitValue ? "--limit '${limitValue}'" : '' + def checkFlag = (params.DRY_RUN == true) ? '--check --diff' : '' + def extraVars = (params.CLEANUP_SNAPSHOTS == true) ? "-e cleanup_old_snapshots=true" : '' + + echo "DRY_RUN parameter: ${params.DRY_RUN}" + echo "Check flag: '${checkFlag}'" + echo "Limit: '${limitValue}'" + if (isDockerPlaybook) { + echo "Docker playbook detected - targeting hosts with 'docker' tag" + } + + sh """ + ansible-playbook \ + -i inventories/inventory.proxmox.yml \ + playbooks/${params.PLAYBOOK} \ + ${limitFlag} \ + ${checkFlag} \ + ${extraVars} \ + -v + """ + } + } + } + } + + post { + success { + echo "Playbook ${params.PLAYBOOK} completed successfully" + } + failure { + echo "Playbook ${params.PLAYBOOK} failed" + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..731c3c7 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Infrastructure +Master Node runs on Plex VM + +# Example Commands +`ansible VMs -m ping` +This runs the ping module on all hosts in the VMs group + +`ansible vpn -m ping` +Runs the ping module on the host named vpn + +`ansible vpn -m ansible.builtin.copy -a "src=/home/jerick/plex/docker-compose.yml dest=/home/jerick/"` +Copied the Plex docker-compose file from plex to vpn + +`ansible-playbook update.yaml -kK` +Runs the update.yml playbook + +/etc/ansible for app directory + + +#update.yaml +ansible-playbook -i inventories/inventory.linux.proxmox.yml update.yaml -kK +this will update all runningVMs and LXCs with the linux tag \ No newline at end of file diff --git a/inventories/inventory.proxmox.yml b/inventories/inventory.proxmox.yml new file mode 100644 index 0000000..f0ee66f --- /dev/null +++ b/inventories/inventory.proxmox.yml @@ -0,0 +1,25 @@ +# Proxmox Dynamic Inventory +# Requires PROXMOX_TOKEN_SECRET environment variable to be set +plugin: community.proxmox.proxmox +url: https://192.168.0.166:8006 +user: dynamic-inventory@pve +token_id: dynamic-inventory +validate_certs: false +want_facts: true + +# Filter to only running machines +filters: + - proxmox_status == 'running' + +# Group by Proxmox tags and type +groups: + vms: "'qemu' in proxmox_type" + lxcs: "'lxc' in proxmox_type" + # Tag-based groups - add tags in Proxmox to auto-group + update_targets: "'update' in (proxmox_tags | default([]))" + docker_hosts: "'docker' in (proxmox_tags | default([]))" + kubernetes: "'k8s' in (proxmox_tags | default([]))" + +compose: + ansible_host: name + '.lan' + ansible_user: 'jenkins' diff --git a/playbooks/dockerPrune.yaml b/playbooks/dockerPrune.yaml new file mode 100644 index 0000000..813d0b5 --- /dev/null +++ b/playbooks/dockerPrune.yaml @@ -0,0 +1,11 @@ +- hosts: VMs + gather_facts: no + tasks: + - name: Prune all unused containers, images, networks, volumes + community.docker.docker_prune: + containers: true + images: true + networks: true + volumes: true + builder_cache: true + diff --git a/playbooks/dockerUpdate.yml b/playbooks/dockerUpdate.yml new file mode 100644 index 0000000..991205b --- /dev/null +++ b/playbooks/dockerUpdate.yml @@ -0,0 +1,57 @@ +# Use with: ansible-playbook -i inventories/inventory.proxmox.yml playbooks/dockerUpdate.yml --limit docker_hosts +- name: Update Docker containers for media-app + hosts: media-app + tasks: + - name: Pull new images for all services + community.docker.docker_compose_v2: + project_src: "{{ item.directory }}" + state: present + loop: + - { directory: "/home/jerick/audiobookshelf" } + - { directory: "/home/jerick/authelia" } + - { directory: "/home/jerick/bazarr" } + - { directory: "/home/jerick/firefly3" } + - { directory: "/home/jerick/gitea" } + - { directory: "/home/jerick/gotify" } + - { directory: "/home/jerick/it-tools" } + - { directory: "/home/jerick/joplin" } + - { directory: "/home/jerick/nginxproxy" } + - { directory: "/home/jerick/ombi" } + - { directory: "/home/jerick/picoshare" } + - { directory: "/home/jerick/romM" } + - { directory: "/home/jerick/tandoor_recipes" } + - { directory: "/home/jerick/tautulli" } + - { directory: "/home/jerick/watchtower" } + - { directory: "/home/jerick/immich" } + +- name: Update Docker containers for media-management + hosts: media-management + tasks: + - name: Pull new images for all services + community.docker.docker_compose_v2: + project_src: "{{ item.directory }}" + state: present + loop: + - { directory: "/home/jerick/docker" } + +- name: Update Docker containers for plex + hosts: plex + tasks: + - name: Pull new images for all services + community.docker.docker_compose_v2: + project_src: "{{ item.directory }}" + state: present + loop: + - { directory: "/home/jerick/plex" } + - { directory: "/home/jerick/plexAutoLanguages" } + +- name: Cleanup + hosts: docker_hosts + tasks: + - name: Prune Docker Images, Networks, etc + community.docker.docker_prune: + containers: true + images: true + networks: true + volumes: true + builder_cache: true