From 71ed6143cd41aca29caf4536bfad8a0acaf88616 Mon Sep 17 00:00:00 2001 From: Kevin Thompson Date: Thu, 7 Aug 2025 14:04:27 -0500 Subject: [PATCH] Formatting, command chaining, exit handling --- roles/inventory/linode/tasks/main.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/roles/inventory/linode/tasks/main.yml b/roles/inventory/linode/tasks/main.yml index 8788c68..6019c7c 100644 --- a/roles/inventory/linode/tasks/main.yml +++ b/roles/inventory/linode/tasks/main.yml @@ -140,34 +140,29 @@ - name: Configure Git user for commits ansible.builtin.shell: | - cd /runner/project - git config --local user.email "awx@ewnix.net" - git config --local user.name "AWX Automation" - # Ensure we're using SSH for the remote + cd /runner/project && + git config --local user.email "awx@ewnix.net" && + git config --local user.name "AWX Automation" && git remote set-url origin git@git.ewnix.net:phlux/ewnix-automation.git delegate_to: localhost ignore_errors: true - name: Ensure SSH key is available for Git operations ansible.builtin.shell: | - # Add git.ewnix.net to known hosts to avoid interactive prompts - ssh-keyscan -t rsa git.ewnix.net >> ~/.ssh/known_hosts 2>/dev/null || true - # Test SSH connection + ssh-keyscan -t rsa git.ewnix.net >> ~/.ssh/known_hosts 2>/dev/null || true && ssh -T git@git.ewnix.net -o StrictHostKeyChecking=no -o ConnectTimeout=10 2>&1 || echo "SSH test completed" delegate_to: localhost ignore_errors: true - name: Commit inventory back to Git ansible.builtin.shell: | - cd /runner/project - git add inventory/linode_hosts.json + cd /runner/project && + git add inventory/linode_hosts.json && if git diff --staged --quiet; then echo "No changes to commit" - exit 0 else - git commit -m "Update Linode inventory - $(date '+%Y-%m-%d %H:%M:%S') [AWX]" - # Use SSH to push - GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30" git push origin HEAD + git commit -m "Update Linode inventory - $(date '+%Y-%m-%d %H:%M:%S') [AWX]" && + GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30" git push origin HEAD && echo "Inventory committed and pushed to git@git.ewnix.net:phlux/ewnix-automation" fi register: git_commit_result