From 8295535ad9c7689855b66fd13914d8ede2325d19 Mon Sep 17 00:00:00 2001 From: Mafyuh Date: Sun, 12 Jan 2025 22:30:10 -0500 Subject: [PATCH] add weekly playbook runs --- .forgejo/workflows/ansible-playbooks.yml | 25 ++++++++++++++----- ...required.yml => maint-reboot-required.yml} | 2 +- ansible/playbooks/{ => weekly}/apt.yml | 0 .../playbooks/{ => weekly}/docker-prune.yml | 0 4 files changed, 20 insertions(+), 7 deletions(-) rename ansible/playbooks/{main-reboot-required.yml => maint-reboot-required.yml} (95%) rename ansible/playbooks/{ => weekly}/apt.yml (100%) rename ansible/playbooks/{ => weekly}/docker-prune.yml (100%) diff --git a/.forgejo/workflows/ansible-playbooks.yml b/.forgejo/workflows/ansible-playbooks.yml index 14e31d8..f284074 100644 --- a/.forgejo/workflows/ansible-playbooks.yml +++ b/.forgejo/workflows/ansible-playbooks.yml @@ -1,6 +1,9 @@ name: Run Ansible Playbook on: + schedule: + # Runs weekly at 3:00 AM every Monday (UTC) + - cron: "0 3 * * 1" workflow_dispatch: inputs: playbook: @@ -8,14 +11,14 @@ on: required: true type: choice options: - - apt.yml - docker-count.yml - docker-login.yml - - docker-prune.yml - git-pull-reset.yml - - main-reboot-required.yml + - maint-reboot-required.yml - ntp.yml - zsh.yml + - weekly/docker-prune.yml + - weekly/apt.yml jobs: run-playbook: @@ -85,10 +88,20 @@ jobs: eval $(ssh-agent -s) ssh-add /root/.ssh/id_rsa - - name: Run the selected playbook + - name: Run Playbooks env: BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }} ANSIBLE_CONFIG: ansible/ansible.cfg run: | - ansible-playbook -i ansible/hosts.ini ./ansible/playbooks/${{ github.event.inputs.playbook }} \ - --extra-vars "bw_access_token=${{ secrets.BW_ACCESS_TOKEN }}" + if [ -z "${{ github.event.inputs.playbook }}" ]; then + echo "Running all playbooks in ansible/playbooks/weekly..." + for playbook in ansible/playbooks/weekly/*.yml; do + echo "Running $playbook..." + ansible-playbook -i ansible/hosts.ini $playbook \ + --extra-vars "bw_access_token=${{ secrets.BW_ACCESS_TOKEN }}" + done + else + echo "Running selected playbook: ${{ github.event.inputs.playbook }}" + ansible-playbook -i ansible/hosts.ini ansible/playbooks/${{ github.event.inputs.playbook }} \ + --extra-vars "bw_access_token=${{ secrets.BW_ACCESS_TOKEN }}" + fi diff --git a/ansible/playbooks/main-reboot-required.yml b/ansible/playbooks/maint-reboot-required.yml similarity index 95% rename from ansible/playbooks/main-reboot-required.yml rename to ansible/playbooks/maint-reboot-required.yml index 3f05d7e..368c4fc 100644 --- a/ansible/playbooks/main-reboot-required.yml +++ b/ansible/playbooks/maint-reboot-required.yml @@ -1,7 +1,7 @@ --- - name: check if system reboot is required hosts: "*" - become: yes + become: true tasks: - name: check if system reboot is required become: true diff --git a/ansible/playbooks/apt.yml b/ansible/playbooks/weekly/apt.yml similarity index 100% rename from ansible/playbooks/apt.yml rename to ansible/playbooks/weekly/apt.yml diff --git a/ansible/playbooks/docker-prune.yml b/ansible/playbooks/weekly/docker-prune.yml similarity index 100% rename from ansible/playbooks/docker-prune.yml rename to ansible/playbooks/weekly/docker-prune.yml