This commit is contained in:
2025-08-07 14:29:52 -05:00
parent 704714499b
commit d56b0ec0da

View File

@@ -39,43 +39,6 @@
delegate_to: localhost delegate_to: localhost
changed_when: true changed_when: true
- name: Show script execution details
ansible.builtin.debug:
msg: |
Script execution results:
Return code: {{ linode_inventory_result.rc }}
Stdout length: {{ linode_inventory_result.stdout | length }}
Stderr length: {{ linode_inventory_result.stderr | length }}
- name: Show stderr if present
ansible.builtin.debug:
msg: "Script stderr: {{ linode_inventory_result.stderr }}"
when: linode_inventory_result.stderr | length > 0
- name: Show stdout if present
ansible.builtin.debug:
msg: "Script stdout: {{ linode_inventory_result.stdout }}"
when: linode_inventory_result.stdout | length > 0
- name: Test API token directly
ansible.builtin.uri:
url: "https://api.linode.com/v4/linode/instances"
method: GET
headers:
Authorization: "Bearer {{ linode_api_token }}"
Content-Type: "application/json"
return_content: yes
status_code: [200, 401, 403]
register: direct_api_test
delegate_to: localhost
- name: Display direct API test results
ansible.builtin.debug:
msg: |
Direct API test results:
Status: {{ direct_api_test.status }}
Response: {{ direct_api_test.json | default('No JSON response') }}
- name: Parse inventory JSON (only if stdout exists) - name: Parse inventory JSON (only if stdout exists)
ansible.builtin.set_fact: ansible.builtin.set_fact:
linode_inventory_data: "{{ linode_inventory_result.stdout | from_json }}" linode_inventory_data: "{{ linode_inventory_result.stdout | from_json }}"
@@ -94,26 +57,12 @@
hosts: [] hosts: []
when: linode_inventory_data is not defined when: linode_inventory_data is not defined
- name: Save inventory to file
ansible.builtin.copy:
content: "{{ linode_inventory_data | to_nice_json }}"
dest: "{{ temp_inventory_path }}"
mode: '0644'
delegate_to: localhost
- name: Display inventory summary - name: Display inventory summary
ansible.builtin.debug: ansible.builtin.debug:
msg: | msg: |
Linode Dynamic Inventory Summary: Linode Dynamic Inventory Summary:
Total hosts discovered: {{ linode_inventory_data._meta.hostvars | length }} Total hosts discovered: {{ linode_inventory_data._meta.hostvars | length }}
Groups created: {{ linode_inventory_data.keys() | reject('equalto', '_meta') | list | length }} Groups created: {{ linode_inventory_data.keys() | reject('equalto', '_meta') | list | length }}
Inventory saved to: {{ temp_inventory_path }}
API Token status: {{ 'Set (' + (linode_api_token[:8] + '...' if linode_api_token | length > 8 else linode_api_token) + ')' if linode_api_token is defined else 'NOT SET' }}
- name: Show raw script output for debugging
ansible.builtin.debug:
var: linode_inventory_result.stdout
when: linode_inventory_result.stdout | length > 0
- name: Show discovered hosts - name: Show discovered hosts
ansible.builtin.debug: ansible.builtin.debug:
@@ -123,21 +72,6 @@
label: "{{ item.key }}" label: "{{ item.key }}"
when: linode_inventory_data._meta.hostvars | length > 0 when: linode_inventory_data._meta.hostvars | length > 0
- name: Create inventory directory in project
ansible.builtin.file:
path: "/runner/project/inventory"
state: directory
mode: '0755'
delegate_to: localhost
- name: Create JSON inventory file in project
ansible.builtin.copy:
content: "{{ linode_inventory_data | to_nice_json }}"
dest: "/runner/project/inventory/linode_hosts.json"
mode: '0644'
delegate_to: localhost
when: linode_inventory_data is defined
- name: Debug current directory and Git status - name: Debug current directory and Git status
ansible.builtin.shell: | ansible.builtin.shell: |
echo "Current directory: $(pwd)" && echo "Current directory: $(pwd)" &&
@@ -151,58 +85,6 @@
delegate_to: localhost delegate_to: localhost
ignore_errors: true ignore_errors: true
- name: Display debug information
ansible.builtin.debug:
msg: |
Debug Git Information:
{{ debug_git_info.stdout }}
Git Config Result:
{{ git_config_result.stdout if git_config_result is defined else 'Not available' }}
Git Commit Result:
{{ git_commit_result.stdout if git_commit_result is defined else 'Not available' }}
- name: Check if inventory file was created
ansible.builtin.stat:
path: "inventory/linode_hosts.json"
register: inventory_file_check
delegate_to: localhost
- name: Display inventory file status
ansible.builtin.debug:
msg: |
Inventory file status:
- Path: inventory/linode_hosts.json
- Exists: {{ inventory_file_check.stat.exists }}
- Size: {{ inventory_file_check.stat.size | default(0) }} bytes
- Location: {{ ansible_env.PWD | default('unknown') }}/inventory/linode_hosts.json
- name: Show current Git status and try manual push
ansible.builtin.shell: |
echo "=== Current working directory ==="
pwd
echo "=== Git status ==="
git status
echo "=== Git log (last commit) ==="
git log --oneline -1
echo "=== Attempting to push ==="
git push origin HEAD 2>&1 || echo "Push failed - check SSH access"
register: manual_git_push
delegate_to: localhost
ignore_errors: true
when: inventory_file_check.stat.exists
- name: Display Git push results
ansible.builtin.debug:
msg: |
Manual Git Push Results:
{{ manual_git_push.stdout }}
Error (if any):
{{ manual_git_push.stderr | default('No errors') }}
when: manual_git_push is defined
- name: Initialize Git if needed and configure - name: Initialize Git if needed and configure
ansible.builtin.shell: | ansible.builtin.shell: |
if [ ! -d ".git" ]; then if [ ! -d ".git" ]; then
@@ -233,20 +115,11 @@
echo "=== SSH config ===" echo "=== SSH config ==="
ls -la ~/.ssh/ 2>/dev/null || echo "No .ssh directory" ls -la ~/.ssh/ 2>/dev/null || echo "No .ssh directory"
echo "=== Test SSH to git.ewnix.net ===" echo "=== Test SSH to git.ewnix.net ==="
ssh -T git@git.ewnix.net -o ConnectTimeout=10 -o StrictHostKeyChecking=no 2>&1 || echo "SSH test completed with exit code $?" timeout 10 ssh -T git@git.ewnix.net -o ConnectTimeout=5 -o StrictHostKeyChecking=no 2>&1 || echo "SSH test completed"
register: ssh_debug register: ssh_debug
delegate_to: localhost delegate_to: localhost
ignore_errors: true ignore_errors: true
- name: Display SSH debug information
ansible.builtin.debug:
msg: |
SSH Debug Results:
{{ ssh_debug.stdout }}
SSH Errors:
{{ ssh_debug.stderr | default('No SSH errors') }}
- name: Create inventory directory - name: Create inventory directory
ansible.builtin.file: ansible.builtin.file:
path: "inventory" path: "inventory"
@@ -262,17 +135,26 @@
delegate_to: localhost delegate_to: localhost
when: linode_inventory_data is defined when: linode_inventory_data is defined
- name: Attempt to commit inventory (simplified) - name: Check if inventory file was created
ansible.builtin.stat:
path: "inventory/linode_hosts.json"
register: inventory_file_check
delegate_to: localhost
- name: Attempt to commit and push inventory
ansible.builtin.shell: | ansible.builtin.shell: |
git_root=$(git rev-parse --show-toplevel 2>/dev/null || echo "") git_root=$(git rev-parse --show-toplevel 2>/dev/null || echo "")
if [ -n "$git_root" ]; then if [ -n "$git_root" ]; then
cd "$git_root" && cd "$git_root" &&
echo "Working in git repository: $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]" &&
echo "Inventory committed locally (push skipped for now)" echo "Committed successfully, attempting push..." &&
timeout 30 git push origin HEAD &&
echo "Push successful!"
fi fi
else else
echo "No git repository found - inventory file created but not committed" echo "No git repository found - inventory file created but not committed"
@@ -283,42 +165,46 @@
when: when:
- linode_inventory_data is defined - linode_inventory_data is defined
- push_to_git | default(true) - push_to_git | default(true)
- inventory_file_check.stat.exists
- name: Display Git operation result - name: Display comprehensive debug information
ansible.builtin.debug: ansible.builtin.debug:
msg: | msg: |
Git operation result: === COMPREHENSIVE DEBUG RESULTS ===
Return code: {{ git_commit_result.rc }}
Output: {{ git_commit_result.stdout }}
Error: {{ git_commit_result.stderr | default('None') }}
when: git_commit_result is defined
- name: Trigger AWX project sync (if AWX API available) Current Directory Info:
ansible.builtin.uri: {% if debug_git_info is defined and debug_git_info.stdout is defined %}
url: "{{ awx_host | default('https://localhost') }}/api/v2/projects/{{ awx_project_id }}/update/" {{ debug_git_info.stdout }}
method: POST {% else %}
headers: Debug info not available
Authorization: "Bearer {{ awx_token }}" {% endif %}
Content-Type: "application/json"
body_format: json
body: {}
status_code: [200, 201, 202]
validate_certs: false
register: project_sync_result
delegate_to: localhost
ignore_errors: true
when:
- awx_api_integration | default(false)
- awx_token is defined
- awx_project_id is defined
- name: Display project sync result SSH Configuration:
ansible.builtin.debug: {% if ssh_debug is defined and ssh_debug.stdout is defined %}
msg: | {{ ssh_debug.stdout }}
AWX Project sync triggered: {% else %}
Status: {{ project_sync_result.status | default('Not attempted') }} SSH debug not available
Response: {{ project_sync_result.json | default('No response') }} {% endif %}
when: project_sync_result is defined
Git Configuration:
{% if git_config_result is defined and git_config_result.stdout is defined %}
{{ git_config_result.stdout }}
{% else %}
Git config not available
{% endif %}
Git Commit/Push Results:
{% if git_commit_result is defined and git_commit_result.stdout is defined %}
{{ git_commit_result.stdout }}
{% else %}
Git commit result not available
{% endif %}
Inventory File Status:
- Exists: {{ inventory_file_check.stat.exists if inventory_file_check is defined else 'Unknown' }}
{% if inventory_file_check is defined and inventory_file_check.stat.exists %}
- Size: {{ inventory_file_check.stat.size }} bytes
{% endif %}
- name: Clean up temporary script - name: Clean up temporary script
ansible.builtin.file: ansible.builtin.file: