Debugging, find git repo root, skip hanging ssh test, create inventory file, commit locally.
This commit is contained in:
@@ -138,32 +138,79 @@
|
|||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: linode_inventory_data is defined
|
when: linode_inventory_data is defined
|
||||||
|
|
||||||
- name: Configure Git user for commits
|
- name: Debug current directory and Git status
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd /runner/project &&
|
echo "Current directory: $(pwd)" &&
|
||||||
git config --local user.email "awx@ewnix.net" &&
|
echo "Directory contents:" &&
|
||||||
git config --local user.name "AWX Automation" &&
|
ls -la &&
|
||||||
git remote set-url origin git@git.ewnix.net:phlux/ewnix-automation.git
|
echo "Git status:" &&
|
||||||
|
git status 2>&1 || echo "Not a git repository" &&
|
||||||
|
echo "Git remote:" &&
|
||||||
|
git remote -v 2>&1 || echo "No git remotes"
|
||||||
|
register: debug_git_info
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Ensure SSH key is available for Git operations
|
- name: Display debug information
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: debug_git_info.stdout_lines
|
||||||
|
|
||||||
|
- name: Initialize Git if needed and configure
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
ssh-keyscan -t rsa git.ewnix.net >> ~/.ssh/known_hosts 2>/dev/null || true &&
|
# Check if we're in a git repo, if not try to find the actual project directory
|
||||||
ssh -T git@git.ewnix.net -o StrictHostKeyChecking=no -o ConnectTimeout=10 2>&1 || echo "SSH test completed"
|
if [ ! -d ".git" ]; then
|
||||||
|
echo "Not in a git repository, checking for git in parent directories"
|
||||||
|
# Try to find the git root
|
||||||
|
git_root=$(git rev-parse --show-toplevel 2>/dev/null || echo "")
|
||||||
|
if [ -n "$git_root" ]; then
|
||||||
|
cd "$git_root"
|
||||||
|
echo "Found git repository at: $git_root"
|
||||||
|
else
|
||||||
|
echo "No git repository found"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi &&
|
||||||
|
git config user.email "awx@ewnix.net" &&
|
||||||
|
git config user.name "AWX Automation" &&
|
||||||
|
git remote set-url origin git@git.ewnix.net:phlux/ewnix-automation.git &&
|
||||||
|
echo "Git configured successfully"
|
||||||
|
register: git_config_result
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Commit inventory back to Git
|
- name: Skip SSH test for now and proceed
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Skipping SSH test to avoid hanging - will attempt Git operations directly"
|
||||||
|
|
||||||
|
- name: Create inventory directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "inventory"
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Create JSON inventory file
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ linode_inventory_data | to_nice_json }}"
|
||||||
|
dest: "inventory/linode_hosts.json"
|
||||||
|
mode: '0644'
|
||||||
|
delegate_to: localhost
|
||||||
|
when: linode_inventory_data is defined
|
||||||
|
|
||||||
|
- name: Attempt to commit inventory (simplified)
|
||||||
ansible.builtin.shell: |
|
ansible.builtin.shell: |
|
||||||
cd /runner/project &&
|
git_root=$(git rev-parse --show-toplevel 2>/dev/null || echo "")
|
||||||
|
if [ -n "$git_root" ]; then
|
||||||
|
cd "$git_root" &&
|
||||||
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"
|
||||||
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]" &&
|
||||||
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30" git push origin HEAD &&
|
echo "Inventory committed locally (push skipped for now)"
|
||||||
echo "Inventory committed and pushed to git@git.ewnix.net:phlux/ewnix-automation"
|
fi
|
||||||
|
else
|
||||||
|
echo "No git repository found - inventory file created but not committed"
|
||||||
fi
|
fi
|
||||||
register: git_commit_result
|
register: git_commit_result
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
Reference in New Issue
Block a user