-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi_get_hosts.yml
45 lines (39 loc) · 1.52 KB
/
api_get_hosts.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
- name: Query API for Hosts over 90 days
hosts: localhost
gather_facts: False
tasks:
- name: Get an AAP API Token and store it as new_token
ansible.builtin.uri:
url: "https://{{ controller_url }}/api/v2/tokens/"
method: POST
user: "{{ username }}"
password: "{{ password }}"
validate_certs: no
force_basic_auth: yes
status_code: 201
return_content: yes
register: new_token
- name: Query API for hosts
ansible.builtin.uri:
url: "https://{{ controller_url }}/api/v2/hosts/?page_size=10000"
headers:
Authorization: "Bearer {{ new_token.json.token }}"
Content-Type: "application/json"
validate_certs: no
follow_redirects: all
return_content: yes
method: "GET"
status_code: 200
register: json_content
- name: Collect Hostname Inventory Name ID and last job run
vars:
_jquery: "results[*].{Name: name , Last_job_run: summary_fields.last_job.finished , InventoryID: summary_fields.inventory.id, InventoryName: summary_fields.inventory.name }"
ansible.builtin.set_fact:
nodedata: "{{nodedata|default({}) | combine ( {item.Name : item.Last_job_run }) }}"
with_items: "{{ json_content.json | json_query(_jquery)}}"
- name: The nodedata
ansible.builtin.debug: var=nodedata
- name: Number of unique endpoints
ansible.builtin.debug:
msg: "Unique endpoints: {{ nodedata | length }}"