Computer Inventorying
Inventory a computer
Details
An inventory report will be uploaded to an API endpoint which will then be processed and added to the ITAM component of the Application for the recording of a devices state. This state will contain the device details and installed software.
Ansible playbook to gather inventory
If ansible is used to conduct the inventory this opens up additional possibilities for the inventory. Namely the use of scheduled jobs from AWX.
playbook/inventory.yaml
- name: Playbook Template
hosts: localhost
become: true
tasks:
- name: Test Packages
ansible.builtin.package_facts:
manager: auto
become: true
# - name: Test output
# ansible.builtin.debug:
# msg: "{{ package.value[0].name }}"
# loop: "{{ ansible_facts.packages | dict2items() }}"
# loop_control:
# loop_var: package
# # label: "{{ package[0].name }}"
- name: Inventory Details
ansible.builtin.set_fact:
details: {
"name": "{{ ansible_hostname }}",
"serial_number": "{{ ansible_product_serial }}",
"uuid": "{{ ansible_product_uuid }}"
}
- name: Inventory Software
ansible.builtin.set_fact:
software: "{{ software | default([]) + [{
'name': package.value[0].name,
'category': package.value[0].category,
'version': package.value[0].version
}] }}"
no_log: true
loop: "{{ ansible_facts.packages | dict2items() }}"
loop_control:
loop_var: package
label: "{{ package.key }}"
- name: Inventory Document
ansible.builtin.set_fact:
report: {
"details": "{{ details }}",
"os": {
"name": "{{ ansible_distribution | lower }}",
"version": "{{ ansible_distribution_version }}",
"version_major": "{{ ansible_distribution_major_version }}"
},
"software": "{{ software }}"
}
- name: Save report
ansible.builtin.copy:
content: "{{ report | to_nice_json }}"
dest: "./aa-{{ ansible_hostname }}.json"
Conduct
the inventory will be gathered using a playbook that will build the inventory report. this report will be uploaded to an API endpoint that will accept the report in it's entirety and process it. At this stage it's unknown if this report will be processed at the time of upload or if it will be cached and processed later.
Inventory report
API Inventory report
{
"details": {
"name": "string",
"serial_number": "string",
"uuid": "string"
},
"os": {
"name": "debian|ubuntu",
"version_major": "major version number",
"version": "as reported"
},
"software": [
{
"name": "string",
"category": "string",
"version": "string"
}
]
}
Report Fields
-
details
-
name
hostname -
serial_number
the serial number of the devicethis field will require normalization to capitol letters as it will be used for matching
-
uuid
the device system GUID/UUIDthis field will require normalization to capitol letters as it will be used for matching
-
-
os
-
name
a choice field to denote os. used for regex filtering. -
version
version of OS as reported -
version_major
major version number, used as version number for the operating system version.
-
-
software
-
name
name of the software -
category
category of the software. apt provides and will be used -
version
version of softwarethis field will require normalization
-
Requirements
-
Upload an inventory to create a new device -
Field Normalization
-
version
to use semver. No semver, then use supplied version from report -
serial_number
normalized to capitol letters -
uuid
normalized to capitol letters
-
Tasks
-
Plan Feature