Formatting, command chaining, exit handling
This commit is contained in:
@@ -140,34 +140,29 @@
|
|||||||
|
|
||||||
- name: Configure Git user for commits
|
- name: Configure Git user for commits
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd /runner/project
|
cd /runner/project &&
|
||||||
git config --local user.email "awx@ewnix.net"
|
git config --local user.email "awx@ewnix.net" &&
|
||||||
git config --local user.name "AWX Automation"
|
git config --local user.name "AWX Automation" &&
|
||||||
# Ensure we're using SSH for the remote
|
|
||||||
git remote set-url origin git@git.ewnix.net:phlux/ewnix-automation.git
|
git remote set-url origin git@git.ewnix.net:phlux/ewnix-automation.git
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Ensure SSH key is available for Git operations
|
- name: Ensure SSH key is available for Git operations
|
||||||
ansible.builtin.shell: |
|
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 &&
|
||||||
ssh-keyscan -t rsa git.ewnix.net >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
||||||
# Test SSH connection
|
|
||||||
ssh -T git@git.ewnix.net -o StrictHostKeyChecking=no -o ConnectTimeout=10 2>&1 || echo "SSH test completed"
|
ssh -T git@git.ewnix.net -o StrictHostKeyChecking=no -o ConnectTimeout=10 2>&1 || echo "SSH test completed"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Commit inventory back to Git
|
- name: Commit inventory back to Git
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd /runner/project
|
cd /runner/project &&
|
||||||
git add inventory/linode_hosts.json
|
git add inventory/linode_hosts.json &&
|
||||||
if git diff --staged --quiet; then
|
if git diff --staged --quiet; then
|
||||||
echo "No changes to commit"
|
echo "No changes to commit"
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
git commit -m "Update Linode inventory - $(date '+%Y-%m-%d %H:%M:%S') [AWX]"
|
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_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"
|
echo "Inventory committed and pushed to git@git.ewnix.net:phlux/ewnix-automation"
|
||||||
fi
|
fi
|
||||||
register: git_commit_result
|
register: git_commit_result
|
||||||
|
Reference in New Issue
Block a user