mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-07 03:00:33 -07:00
* add systemd_info module * fix object results * apply review changes * apply module change and add doc_fragments * removed use_unsafe_shell and doc_fragments/systemd * fix unitname description doc * fixed doc, replaced systemctl show syntax, added base prop result doc * fix documentation * fix RV values in description * fix RV() description values * add get_bin_path try/fail and remove list() * fix doc, removed try block * add Archlinux in integration test
107 lines
No EOL
4.5 KiB
YAML
107 lines
No EOL
4.5 KiB
YAML
# Copyright (c) Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
- name: Gather all units from shell
|
|
ansible.builtin.command: systemctl list-units --no-pager --type service,target,socket,mount --all --plain --no-legend
|
|
register: all_units
|
|
|
|
- name: Assert command run successfully
|
|
ansible.builtin.assert:
|
|
that:
|
|
- all_units.rc == 0
|
|
|
|
- name: Gather all units
|
|
community.general.systemd_info:
|
|
register: units_all
|
|
|
|
- name: Check all units exists
|
|
ansible.builtin.assert:
|
|
that:
|
|
- units_all is defined
|
|
- units_all.units | length == all_units.stdout_lines | length
|
|
success_msg: "Success: All units collected."
|
|
|
|
- name: Build all units list
|
|
set_fact:
|
|
shell_units: "{{ all_units.stdout_lines | map('split') | list }}"
|
|
|
|
- name: Check all units properties
|
|
ansible.builtin.assert:
|
|
that:
|
|
- units_all.units[item[0]].name == item[0]
|
|
- units_all.units[item[0]].loadstate == item[1]
|
|
- units_all.units[item[0]].activestate == item[2]
|
|
- units_all.units[item[0]].substate == item[3]
|
|
loop: "{{ shell_units }}"
|
|
loop_control:
|
|
label: "{{ item[0] }}"
|
|
|
|
- name: Gather systemd-journald.service properties from shell
|
|
ansible.builtin.command: systemctl show systemd-journald.service -p Id,LoadState,ActiveState,SubState,FragmentPath,MainPID,ExecMainPID,UnitFileState,UnitFilePreset,Description,Restart
|
|
register: journald_prop
|
|
|
|
- name: Assert command run successfully
|
|
ansible.builtin.assert:
|
|
that:
|
|
- journald_prop.rc == 0
|
|
|
|
- name: Gather systemd-journald.service
|
|
community.general.systemd_info:
|
|
unitname:
|
|
- systemd-journald.service
|
|
register: journal_unit
|
|
|
|
- name: Check unit facts and all properties
|
|
ansible.builtin.assert:
|
|
that:
|
|
- journal_unit.units is defined
|
|
- journal_unit.units['systemd-journald.service'] is defined
|
|
- journal_unit.units['systemd-journald.service'].name is defined
|
|
- journal_unit.units['systemd-journald.service'].loadstate is defined
|
|
- journal_unit.units['systemd-journald.service'].activestate is defined
|
|
- journal_unit.units['systemd-journald.service'].substate is defined
|
|
- journal_unit.units['systemd-journald.service'].fragmentpath is defined
|
|
- journal_unit.units['systemd-journald.service'].mainpid is defined
|
|
- journal_unit.units['systemd-journald.service'].execmainpid is defined
|
|
- journal_unit.units['systemd-journald.service'].unitfilestate is defined
|
|
- journal_unit.units['systemd-journald.service'].unitfilepreset is defined
|
|
success_msg: "Success: All properties collected."
|
|
|
|
- name: Create dict of properties from shell
|
|
ansible.builtin.set_fact:
|
|
journald_shell: "{{ dict(journald_prop.stdout_lines | map('split', '=', 1) | list) }}"
|
|
|
|
- name: Check properties content
|
|
ansible.builtin.assert:
|
|
that:
|
|
- journal_unit.units['systemd-journald.service'].name == journald_shell.Id
|
|
- journal_unit.units['systemd-journald.service'].loadstate == journald_shell.LoadState
|
|
- journal_unit.units['systemd-journald.service'].activestate == journald_shell.ActiveState
|
|
- journal_unit.units['systemd-journald.service'].substate == journald_shell.SubState
|
|
- journal_unit.units['systemd-journald.service'].fragmentpath == journald_shell.FragmentPath
|
|
- journal_unit.units['systemd-journald.service'].mainpid == journald_shell.MainPID
|
|
- journal_unit.units['systemd-journald.service'].execmainpid == journald_shell.ExecMainPID
|
|
- journal_unit.units['systemd-journald.service'].unitfilestate == journald_shell.UnitFileState
|
|
- journal_unit.units['systemd-journald.service'].unitfilepreset == journald_shell.UnitFilePreset
|
|
success_msg: "Success: Property values are correct."
|
|
|
|
- name: Gather systemd-journald.service extra properties
|
|
community.general.systemd_info:
|
|
unitname:
|
|
- systemd-journald.service
|
|
extra_properties:
|
|
- Description
|
|
- Restart
|
|
register: journal_extra
|
|
|
|
- name: Check new properties
|
|
ansible.builtin.assert:
|
|
that:
|
|
- journal_extra.units is defined
|
|
- journal_extra.units['systemd-journald.service'] is defined
|
|
- journal_extra.units['systemd-journald.service'].description is defined
|
|
- journal_extra.units['systemd-journald.service'].restart is defined
|
|
- journal_extra.units['systemd-journald.service'].description == journald_shell.Description
|
|
- journal_extra.units['systemd-journald.service'].restart == journald_shell.Restart
|
|
success_msg: "Success: Extra property values are correct." |