-
Notifications
You must be signed in to change notification settings - Fork 2
/
discover_system_state.yml
95 lines (84 loc) · 4.08 KB
/
discover_system_state.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
83
84
85
86
87
88
89
90
91
92
93
94
---
- hosts: all
vars:
controller_hostname: "{{ lookup('env', 'HOSTNAME') }}"
controller_hostname_domain: "{{ lookup('env', 'HOSTNAME').split('.')[1:] | join('.') }}"
controller_domainname: "{{ lookup('env', 'DOMAINNAME') | default(controller_hostname_domain, true) }}"
tasks:
- name: Wait for {{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_major_version'] }} host {{inventory_hostname}} connection
wait_for_connection:
- name: Assign random RFC1981 net prefix
set_fact:
random_net_prefix: "192.168.{{ 128 | random + 127 }}"
- name: Assign gadget net prefix from env or random default
set_fact:
gadget_net_prefix: "{{ lookup('env', 'GADGET_NET_PREFIX') | default(random_net_prefix, true) }}"
- name: Assign gadget net domain from env or controller default
set_fact:
gadget_net_domain: "{{ lookup('env', 'GADGET_NET_DOMAIN') | default(controller_domainname, true) }}"
#
# Hardware
#
- name: Discover hardware model according to device tree
# RPi model strings end with null character which must be stripped
ansible.builtin.shell: cat /proc/device-tree/model | rev | cut -c 1- | rev
register: dt_hardware_model
- name: Discover hardware serial number
ansible.builtin.shell: cat /sys/firmware/devicetree/base/serial-number | rev | cut -c 1- | rev
register: sys_serial_number
#
# Kernel state
#
# is_config_mounted == 0 indicates configfs is mounted
- name: Check if configfs is mounted
ansible.builtin.shell: mountpoint /sys/kernel/config/
register: is_configfs_mounted
#
# Kernel modules
#
- name: Check if libcomposite is loaded
ansible.builtin.shell: "{ { lsmod | grep libcomposite >/dev/null; } && echo 'loaded'; } || echo 'not loaded'"
register: is_libcomposite_loaded
#
- name: Check if dwc2 is loaded
ansible.builtin.shell: "{ { lsmod | grep dwc2 >/dev/null; } && echo 'loaded'; } || echo 'not loaded'"
register: is_dwc2_loaded
# - name: Get domain of controller
# ansible.builtin.shell: "domainname"
# register: controller_domain
# delegate_to: localhost
# become: no
# - name: Update the /etc/hosts file with node name
# lineinfile:
# path: "/etc/hosts"
# regexp: ".*\t{{ansible_hostname}}"
# line: "{{ ansible_br0.ipv4.address }}\t{{ ansible_hostname }}"
# # line: "{{ gadget_net_prefix }}\t{{ ansible_hostname }}"
# state: present
# backup: yes
#
# Display results
#
- name: "Target {{ inventory_hostname }} report"
debug:
msg:
# - "device links - {{ ansible_device_links['ids'] | to_nice_json }}"
# - "devices - {{ ansible_devices | to_json }}"
# - "ansible facts - {{ ansible_facts | to_json }}"
# - "random gadget_net_prefix - {{ gadget_net_prefix }}"
# - "random - {{ 126 | random }}"
- "Hardware - {{ dt_hardware_model.stdout }}"
- "Architecture - {{ ansible_architecture }}"
- "Serial Number - {{ sys_serial_number.stdout_lines }}"
- "OS - {{ ansible_distribution }} {{ ansible_distribution_major_version }} {{ ansible_distribution_release }} "
- "cmdline modules-load - {{ ansible_cmdline['modules-load'] }}"
- "configfs status - {{ is_configfs_mounted.stdout }}"
- "libcomposite module - {{ is_libcomposite_loaded.stdout }}"
- "dwc2 module - {{ is_dwc2_loaded.stdout }}"
- "controller_hostname - {{ controller_hostname }}"
- "controller_domainname - {{ controller_domainname }}"
- "controller_hostname_domain - {{ controller_hostname_domain }}"
- "gadget_net_domain - {{ gadget_net_domain }}"
- "ansible_hostname - {{ ansible_hostname }}"
- "ansible_br0.ipv4.address - {{ ansible_br0.ipv4.address}}"
# - "gadget_net_prefix.1 - '{{ gadget_net_prefix }}.1'"