Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0a5c320c authored by Autodistries's avatar Autodistries
Browse files

added and upgraded a bunch of checks

parent 4b717e48
No related branches found
No related tags found
1 merge request!1Refactoring, new features
- hosts: sniffers
gather_facts: false
become: yes
become_user: root
any_errors_fatal: true
tasks:
#GPIO status
- name: GPIO status test
shell: pinctrl get 18 | awk -F" " '{print $9}'
register: result
- name: test if GPS module disabled
set_fact:
falg_failed_gpio_off: "GPS module is disabled"
when: result.stdout != 'input'
# when something is connected, running this prevents gpsd from using that data which forces a reboot
- name: try to get data from the GPIO pins (disabled)
shell: |
gpioPresenceTest=$(mktemp /tmp/test-XXXXXX.gpio)
if [ $(type gpsmon >/dev/null; echo $?) != 0 ]; then
echo 3
fi
timeout 1.2 bash -c 'while true; do sudo gpioget 4 15; done' >> $gpioPresenceTest
if [ $(cat $gpioPresenceTest | sort | uniq | wc -l) != 2 ]; then
echo 2
fi
echo 0
register: _gpiotest
failed_when: false
when: false
no_log: true
# sudo gpiomon 4 15 is too brutal and prevents further communication.
# gpioget 4 15 is the same. idk what to do
- name: interpret gpio reception failure (disabled)
fail:
msg: >-
{% if _gpiotest.rc == 2 %}
no output from GPIO was found. did you plug in the gps correctly ?
{% elif _gpiotest.rc == 3 %}
the command gpsmon does not exist. Is gpsd properly installed?
{% else %}
Unexpected return code: {{ _gpiotest.rc }}. Check stderr: {{_gpiotest}}
{% endif %}
when: false and _gpiotest.rc != 0
ignore_errors: true
- name: check pps reception
shell: |
ppsPresenceTest=$(mktemp /tmp/test-XXXXXX.pps)
if [ $(type ppstest >/dev/null; echo $?) != 0 ]; then
exit 3
fi
timeout 2.2s sudo ppstest /dev/pps0 > $ppsPresenceTest
if [ $(cat $ppsPresenceTest | wc -l) -lt 4 ]; then
exit 2
fi
exit 0
register: _ppscheck
ignore_errors: true
no_log: true
failed_when: false
- name: interpret pps reception failure
fail:
msg: >-
{% if _ppscheck.rc == 2 %}
no output from PPS was found
{% elif _ppscheck.rc == 3 %}
the command ppstest does not exist. Is pps properly installed?
{% else %}
Unexpected return code: {{ _ppscheck.rc }}, check stderr: {{ _ppscheck }}
{% endif %}
when: _ppscheck.rc != 0
ignore_errors: true
- name: check gps position reception
shell: |
if [ $(type gpspipe >/dev/null; echo $?) != 0 ]; then
exit 3
fi
if [ $(timeout 1.2s gpspipe --nmea -n 10 >/dev/null ; echo $?) != 0 ]; then
exit 2
fi
exit 0
register: _gpscheck
failed_when: false
no_log: true
ignore_errors: true
- name: interpret gps reception failure
fail:
msg: >-
{% if _gpscheck.rc == 2 %}
no position from GPS was found. Either wait a minute, or reboot the device
{% elif _gpscheck.rc == 3 %}
the command gpspipe does not exist. Is gpsd properly installed?
{% else %}
Unexpected return code: {{ _gpscheck.rc }}, check stderr: {{ _gpscheck }}
{% endif %}
when: _gpscheck.rc != 0
ignore_errors: true
- name: stop if fails encountered
fail:
msg: GPIO components and gps seem badly configured; see previous errors for this device !
when: _gpiotest.rc | default(0) != 0 or _gpscheck.rc != 0 or _ppscheck.rc != 0
- hosts: sniffers
gather_facts: false
become: yes
become_user: root
tasks:
#GPIO status
- name: GPIO status test
shell: pinctrl get 18 | awk -F" " '{print $9}'
register: result
- name: GPS module enabled
debug:
msg: "GPS module is enabled"
when: result.stdout == 'input'
- name: GPS module disabled
debug:
msg: "GPS module is disabled"
when: result.stdout != 'input'
- hosts: sniffers
name: Check configuration
#gather_facts: false
tasks:
- name: date
command: date
register: result_date
- name: Time verification
debug:
msg: "Date and time: {{ result_date.stdout }}"
- ansible.builtin.git:
repo: https://mitik-sens-mod:glpat-F9S1EPn2KKts_a8syNWu@gitlab.inria.fr/gfarhiri/mitik-sens-mod
dest: ./mitik-sens-mod
update: false
clone: false
- hosts: sniffers
name: Check remote config files
#gather_facts: false
gather_facts: no
vars:
file_combinations:
- local_file: "../files/99-unmanaged-devices.conf"
remote_file: "/etc/NetworkManager/conf.d/99-unmanaged-devices.conf"
- local_file: "../files/72-wlan-geo-dependent.rules"
remote_file: "/etc/udev/rules.d/72-wlan-geo-dependent.rules"
- local_file: "../files/gpsd"
remote_file: "/etc/default/gpsd"
- local_file: "../files/gpsd.socket"
remote_file: "/lib/systemd/system/gpsd.socket"
- local_file: "../files/chrony.conf"
remote_file: "/etc/chrony/chrony.conf"
- local_file: "../files/positionGetter.sh"
remote_file: "/home/{{ansible_ssh_user}}/positionGetter.sh"
tasks:
- name: Get SHA256 checksum for each remote file
stat:
path: "{{ item.remote_file }}"
checksum_algorithm: sha256
register: remote_file_checksums
loop: "{{ file_combinations }}"
- name: Get SHA256 checksum for each local file
stat:
follow: true
path: "{{ item.local_file | realpath }}"
checksum_algorithm: sha256
register: local_file_checksums
delegate_to: localhost
loop: "{{ file_combinations }}"
- debug:
var: item
loop: "{{ local_file_checksums.results | zip(remote_file_checksums.results) | list }}"
- name: Compare local and remote files
fail:
msg: "Local and remote files are different"
when: item[0].stat.checksum != item[1].stat.checksum
loop: "{{ local_file_checksums.results | zip(remote_file_checksums.results) | list }}"
loop_control:
label: "{{ item[0].item }}"
delegate_to: localhost
......@@ -3,9 +3,10 @@
become: yes
become_user: root
vars:
active_interfaces: "{{ ansible_interfaces | select('match', '^(wifi)[0-9]+') }}"
# this si not compatible with having multiple sniffers nichknamed the same...
interfaces_list_raw: >-
{{
hostvars[inventory_hostname]
......@@ -15,21 +16,55 @@
| map(attribute='value')
}}
# removed macaddress
# removed macaddress
interface_query: >-
[].[device, module, type]
interfaces_formated_list: >-
{{ interfaces_list_raw | json_query(interface_query) | map('join', ', ') }}
interfaces_unformated_list: >-
{{ interfaces_list_raw | json_query(interface_query) }}
tasks:
#Interfaces status
# - debug:
# msg: "{{hostvars}}"
# Interfaces status
- name: Interfaces connected
debug:
#var: interfaces_formated_list
msg: "{{ interfaces_formated_list }}"
msg: "{{ interfaces_unformated_list | map('join', ', ') }}"
- name: warn about wlan devices (should be wifi)
debug:
msg: "device has interfaces named wlanX; this is unusual"
when: interfaces_unformated_list | flatten | select('search', '^wlan.+') | length != 0
# Set the length of the first host's interface list
- name: Set length of the first host's interface list
set_fact:
first_host_interface_length: "{{ interfaces_unformated_list | length }}"
when: inventory_hostname == groups['all'][0]
# Propagate the length to all hosts
- name: Propagate first host's interface length to all hosts
set_fact:
first_host_interface_length: "{{ hostvars[groups['all'][0]].first_host_interface_length }}"
when: inventory_hostname != groups['all'][0]
# Check if the lists are of the same length
- name: set failed flag if the number of interfaces is not the same across nodes
fail:
msg: "The number of interfaces is not the same across hosts."
when: interfaces_unformated_list | length != first_host_interface_length | int
ignore_errors: yes
# Check if any interface that is not wifi0 has a type other than unknown
- name: set failed flag if non-wifi0 interfaces have a type other than unknown (this means no monitor mode)
fail:
msg: "wifiX interfaces found in non-monitor mode !!"
when: interfaces_unformated_list | selectattr(2, 'ne', 'unknown') | selectattr(0, 'ne', 'wifi0') | list | length > 0
ignore_errors: yes
- name: failure, stop the playbook
fail:
msg: interfaces tests failed. check the two previous tasks !
when: interfaces_unformated_list | selectattr(2, 'ne', 'unknown') | selectattr(0, 'ne', 'wifi0') | list | length > 0 or interfaces_unformated_list | length != first_host_interface_length | int
any_errors_fatal: true
- debug:
msg: "Interfaces seem to be fine !"
# - import_playbook: test_interfaces_status.yml
# - import_playbook: test_GPIO_status.yml
- import_playbook: test_systemctl_services.yml
# - import_playbook: test_time.yml
- import_playbook: test_time.yml
......@@ -45,8 +45,6 @@
fail:
msg: "{{ansible_hostname}} failed systemctl checks"
when: "not service_statuses is subset(expected_statuses)"
ignore_errors: false
register: _failures
- debug:
msg: "systemctl and systemd seem to be fine !"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment