-
Notifications
You must be signed in to change notification settings - Fork 97
/
collect.yml
82 lines (75 loc) · 2.61 KB
/
collect.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2016, Dag Wieers <[email protected]>
#
# This playbook collects system information from the Ansible fact cache.
# It is intended to be used whenever systems undergo important changes.
- hosts: computers
gather_facts: no
tasks:
- name: Collect hardware info
when: use_cache is not defined
block:
- name: Update facts cache
setup:
- name: Update product info
win_product_facts:
when: use_cache is not defined
- name: Update disk info
win_disk_facts:
when: use_cache is not defined
- name: Create CSV log entry
set_fact:
csv_entry: >-
"{{ ansible_date_time.date }} {{ ansible_date_time.time }}";
"{{ ansible_hostname|upper }}";
"{{ ansible_system_description }}";
"{{ ansible_fqdn }}";
"{{ ansible_os_name }}";
"{{ ansible_distribution_version }}";
"{{ ansible_architecture }}";
"{{ (ansible_interfaces|first).macaddress|default(mac|default(''))|upper }}";
"{{ ansible_ip_addresses|first }}";
"{{ ansible_processor[1] }}";
"{{ (ansible_memtotal_mb/1024)|round|int }}GB";
"{{ disk.bus_type }}";
"{{ disk.media_type }}";
"{{ disk.model }}";
"{{ (disk.size/1000|pow(3))|round|int }}GB";
"{{ disk.firmware_version }}";
"{{ ansible_system_vendor }}";
"{{ ansible_product_name }}";
"{{ ansible_product_serial }}";
"{{ ansible_bios_version }}";
"{{ ansible_bios_date }}";
"{{ ansible_os_product_id|default('') }}";
"{{ ansible_os_product_key|default('') }}";
"{{ ansible_lastboot }}";
"{{ ansible_win_rm_certificate_expires }}";
vars:
unknown_disks: # Stub disk to avoid errors/workarounds
- system_disk: yes
physical_disk:
bus_type: ''
media_type: ''
model: ''
size: 0
firmware_version: ''
disk: '{{ (ansible_facts.disks|default(unknown_disks)|selectattr("system_disk")|first).physical_disk }}'
- hosts: computers
serial: 1
tasks:
- name: Add or update changes to systems.csv
lineinfile:
line: '{{ csv_entry }}'
regexp: '; "{{ ansible_hostname|upper }}";'
dest: /home/dag/home-made/crombeen/systems.csv
state: present
create: yes
delegate_to: localhost
- name: Add system changes to systems-log.csv
lineinfile:
line: '{{ csv_entry }}'
regexp: '^{{ ansible_date_time.date }} {{ ansible_date_time.time }};{{ ansible_hostname }};'
dest: /home/dag/home-made/crombeen/systems-log.csv
state: present
create: yes
delegate_to: localhost