fix: improve Ansible installation and upgrade process in update script

This commit is contained in:
Menno van Leeuwen 2025-01-20 23:43:35 +01:00
parent d6950dcae8
commit 65948ed0d3
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -65,16 +65,21 @@ if [[ "$RUN_HA" == true ]]; then
fi
if [[ "$RUN_ANSIBLE" == true ]]; then
if command -v ansible-playbook &> /dev/null; then
if ! command -v ansible-playbook &> /dev/null; then
printfe "%s\n" "yellow" "Ansible is not installed, installing it with pipx..."
pipx install --include-deps ansible ansible-lint
if [[ $? -ne 0 ]]; then
printfe "%s\n" "red" "Failed to install Ansible."
exit 1
fi
fi
printfe "%s\n" "cyan" "Upgrading Ansible packages..."
cd $HOME/dotfiles/config/ansible && ansible-playbook -i $HOME/dotfiles/config/ansible/inventory.ini $HOME/dotfiles/config/ansible/main.yml --extra-vars "hostname=$DOTF_HOSTNAME" --limit $DOTF_HOSTNAME --ask-become-pass
cd $HOME/dotfiles/config/ansible && ansible-playbook -i $HOME/dotfiles/config/ansible/inventory.ini $HOME/dotfiles/config/ansible/main.yml --extra-vars "hostname=$DOTF_HOSTNAME" --extra-vars "ansible_user=$USER" --limit $DOTF_HOSTNAME --ask-become-pass
if [[ $? -ne 0 ]]; then
printfe "%s\n" "red" "Failed to upgrade Ansible packages."
exit 1
fi
else
printfe "%s\n" "red" "Ansible is not installed."
exit 1
fi
fi