Formatting, command chaining, exit handling
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user