Several changes here
This commit is contained in:
@@ -123,14 +123,96 @@
|
||||
label: "{{ item.key }}"
|
||||
when: linode_inventory_data._meta.hostvars | length > 0
|
||||
|
||||
- name: Create JSON inventory file for AWX
|
||||
ansible.builtin.template:
|
||||
src: linode_hosts.json.j2
|
||||
dest: "{{ linode_inventory_output_dir }}/linode_hosts.json"
|
||||
- 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: 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
|
||||
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 -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
|
||||
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
|
||||
echo "Inventory committed and pushed to git@git.ewnix.net:phlux/ewnix-automation"
|
||||
fi
|
||||
register: git_commit_result
|
||||
delegate_to: localhost
|
||||
ignore_errors: true
|
||||
when:
|
||||
- linode_inventory_data is defined
|
||||
- push_to_git | default(true)
|
||||
|
||||
- name: Display Git operation result
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
Git operation result:
|
||||
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)
|
||||
ansible.builtin.uri:
|
||||
url: "{{ awx_host | default('https://localhost') }}/api/v2/projects/{{ awx_project_id }}/update/"
|
||||
method: POST
|
||||
headers:
|
||||
Authorization: "Bearer {{ awx_token }}"
|
||||
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
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
AWX Project sync triggered:
|
||||
Status: {{ project_sync_result.status | default('Not attempted') }}
|
||||
Response: {{ project_sync_result.json | default('No response') }}
|
||||
when: project_sync_result is defined
|
||||
|
||||
- name: Clean up temporary script
|
||||
ansible.builtin.file:
|
||||
path: "{{ linode_inventory_output_dir }}/linode_inventory.py"
|
||||
|
Reference in New Issue
Block a user