39 lines
1.5 KiB
YAML
39 lines
1.5 KiB
YAML
---
|
|
- name: Gather system inventory from Red Hat Insights API
|
|
hosts: localhost
|
|
gather_facts: false
|
|
vars:
|
|
insights_api_url: "https://console.redhat.com/api/inventory/v1/hosts" # Red Hat Insights Inventory API endpoint
|
|
insights_api_token: "your_access_token" # Replace with your Red Hat API access token (offline token from console.redhat.com)
|
|
# Optional parameters for filtering
|
|
per_page: 50
|
|
page: 1
|
|
|
|
tasks:
|
|
- name: Query Red Hat Insights API for host inventory
|
|
uri:
|
|
url: "{{ insights_api_url }}?per_page={{ per_page }}&page={{ page }}"
|
|
method: GET
|
|
headers:
|
|
Authorization: "Bearer {{ insights_api_token }}"
|
|
Accept: "application/json"
|
|
return_content: true
|
|
validate_certs: true # Set to false if needed, but not recommended
|
|
register: api_response
|
|
|
|
- name: Display the inventory response
|
|
debug:
|
|
var: api_response.json
|
|
|
|
- name: Save inventory to file
|
|
copy:
|
|
content: "{{ api_response.json | to_nice_json }}"
|
|
dest: /root/rhel_insights_inventory.json
|
|
|
|
# Notes:
|
|
# - Obtain an offline API token from https://console.redhat.com/openshift/token
|
|
# - Ensure your systems are registered with Red Hat Insights for them to appear in the inventory.
|
|
# - For production, secure the token with ansible-vault or environment variables.
|
|
# - Install any required modules if needed (uri is built-in).
|
|
# - This fetches a paginated list of hosts; adjust 'per_page' and 'page' or loop for full inventory.
|