Skip to content

Commit

Permalink
feat: cron
Browse files Browse the repository at this point in the history
  • Loading branch information
janikvonrotz committed Feb 26, 2025
1 parent a457280 commit d094b1c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ jobs:
- name: Copy ansible config
run: cp ansible.cfg.template ansible.cfg
- name: Run task test-localhost
run: ./task test-localhost
run: ./task test-localhost
- name: Run task test-scripts
run: ./task test-scripts
2 changes: 1 addition & 1 deletion roles/cron/files/cron-job-list
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ done
: ${CRONTAB_USERNAME:="$USERNAME"}

# Fetch and list the Ansible jobs from the crontab
sudo crontab -u "$CRONTAB_USERNAME" -l | grep '^#Ansible: ' | sed 's/^#Ansible: //'
sudo crontab -u "$CRONTAB_USERNAME" -l | awk '/^#Ansible: / {getline nextline; print $1, $2, $3, $4, $5}'
2 changes: 1 addition & 1 deletion roles/matomo/tasks/matomo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
- name: Cron job to run {{ role_name }} background jobs
ansible.builtin.cron:
name: Run {{ role_name }} background jobs
minute: "*/5"
minute: "5"
job: docker exec -u root {{ matomo_hostname }} bash -c "/usr/local/bin/php /var/www/html/console core:archive --url={{ matomo_url }} > /var/log/matomo-archive.log"
65 changes: 40 additions & 25 deletions task
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ function help() {
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "install" "" "Install Ansible and dependencies with uv."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "install-exo" "" "Install Exoscale CLI."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "upgrade" "" "Upgrade Ansible and dependencies with uv."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "llm-update" "[path][prompt]" "Feed role files with prompt to LLM and apply file changes."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "update-with-llm" "[path][prompt]" "Feed role files with prompt to LLM and apply file changes."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "lint" "" "Lint Ansible roles and playbooks."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "galaxy-build" "" "Create tarball of collection."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "galaxy-publish" "" "Publish tarball to Ansible Galaxy."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "node-install" "" "Install build dependencies."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "node-dev" "" "Start vuepress development server."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "node-build" "" "Create vuepress build."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "node-serve-build" "" "Serve vuepress build."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "build-galaxy" "" "Create tarball of collection."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "publish-galaxy" "" "Publish tarball to Ansible Galaxy."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "install-node" "" "Install build dependencies."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "dev-node" "" "Start vuepress development server."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "build-node" "" "Create vuepress build."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "serve-node-build" "" "Serve vuepress build."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "list-hosts" "[path]" "Lists all hosts of an inventory."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "version" "" "Show tool versions."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "source" "" "Source the Python virtual env."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "test-localhost" "[clean]" "Deploy to localhost. Pass option 'clean' to clean up."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "test-scripts" "" "Install and test scripts."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "show-passwordless-sudo" "[username]" "Give instructions to setup passwordless sudo."
printf "| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n" "llm-update" "[path]" "Feed role files with prompt to LLM and apply updates with git path."

echo
}
Expand All @@ -45,6 +45,8 @@ if [[ -a ".env" ]]; then
export $(cat .env | sed 's/^#.*//g' | xargs)
fi

# Ansible Vault commands

function generate-vault-password() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi
if test -z "$2"; then echo "\$1 is empty"; exit; fi
Expand Down Expand Up @@ -134,6 +136,7 @@ show-vault-file() {
rm -f "$TEMP_PART_FILE"
}

# Environment commands

function init-venv() {
if [ ! -d "venv$GIT_BRANCH" ]; then
Expand Down Expand Up @@ -165,30 +168,36 @@ function install-exo() {
curl -fsSL https://raw.githubusercontent.com/exoscale/cli/master/install-latest.sh | sh
}

function version() {
activate-venv
uv --version
ansible --version
}

function show-passwordless-sudo() {
USER=${1:-"$USERNAME"}
echo "echo \"$USER ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
}

# Ansible commands

function upgrade() {
echo "Update Ansible"
uv pip install --upgrade ansible
}

# Ansible Invenotry commands

function list-hosts() {
if test -z "$1"; then echo "\$1 is empty"; exit; fi

activate-venv
ansible -i $1 all --list-hosts
}

function version() {
activate-venv
uv --version
ansible --version
}
# Ansible Galaxy commands

function show-passwordless-sudo() {
USER=${1:-"$USERNAME"}
echo "echo \"$USER ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
}

function galaxy-build() {
function build-galaxy() {
activate-venv
VERSION=$(yq eval '.version' galaxy.yml)
NAMESPACE=$(yq eval '.namespace' galaxy.yml)
Expand All @@ -198,7 +207,7 @@ function galaxy-build() {
mv $NAMESPACE-$NAME-$VERSION.tar.gz tmp/
}

function galaxy-publish() {
function publish-galaxy() {
activate-venv
VERSION=$(yq eval '.version' galaxy.yml)
NAMESPACE=$(yq eval '.namespace' galaxy.yml)
Expand All @@ -207,6 +216,8 @@ function galaxy-publish() {
ansible-galaxy collection publish tmp/$NAMESPACE-$NAME-$VERSION.tar.gz --token "$GALAXY_API_TOKEN"
}

# Test commands

function test-localhost() {
activate-venv
version
Expand All @@ -229,9 +240,13 @@ function test-localhost() {
fi
}

function test-scripts() {
echo "Install cron scripts"
}

# LLM Commands

function llm-update() {
function update-with-llm() {
if test -z "$1"; then
echo "\$1 is empty.";
exit 1;
Expand Down Expand Up @@ -320,16 +335,16 @@ else
help task
exit 1
;;
node-install)
install-node)
npm install
;;
node-dev)
dev-node)
npm run dev
;;
node-build)
build-node)
npm run build
;;
node-serve-build)
serve-node-build)
cd .vuepress/dist
npx serve
;;
Expand Down

0 comments on commit d094b1c

Please sign in to comment.