mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Add new systemd_info module (#9764)
* 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
This commit is contained in:
parent
2b6f4ba299
commit
8425464c0a
5 changed files with 506 additions and 0 deletions
10
tests/integration/targets/systemd_info/aliases
Normal file
10
tests/integration/targets/systemd_info/aliases
Normal file
|
@ -0,0 +1,10 @@
|
|||
# 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
|
||||
|
||||
needs/root
|
||||
azp/posix/1
|
||||
skip/aix
|
||||
skip/freebsd
|
||||
skip/osx
|
||||
skip/macos
|
26
tests/integration/targets/systemd_info/tasks/main.yml
Normal file
26
tests/integration/targets/systemd_info/tasks/main.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
# 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: skip Alpine
|
||||
meta: end_host
|
||||
when: ansible_distribution == 'Alpine'
|
||||
|
||||
- name: check ansible_service_mgr
|
||||
ansible.builtin.assert:
|
||||
that: ansible_service_mgr == 'systemd'
|
||||
|
||||
- name: Test systemd_facts
|
||||
block:
|
||||
|
||||
- name: Run tests
|
||||
import_tasks: tests.yml
|
||||
|
||||
when: >
|
||||
(ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version is version('7', '>=')) or
|
||||
ansible_distribution == 'Fedora' or
|
||||
(ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('15.04', '>=')) or
|
||||
(ansible_distribution == 'Debian' and ansible_distribution_version is version('8', '>=')) or
|
||||
ansible_os_family == 'Suse' or
|
||||
ansible_distribution == 'Archlinux'
|
107
tests/integration/targets/systemd_info/tasks/tests.yml
Normal file
107
tests/integration/targets/systemd_info/tasks/tests.yml
Normal file
|
@ -0,0 +1,107 @@
|
|||
# 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."
|
Loading…
Add table
Add a link
Reference in a new issue