Skip to content

Commit a2560dc

Browse files
committed
[Linux] Update desktop environment with desktop session
Signed-off-by: Qi Zhang <[email protected]>
1 parent 681f330 commit a2560dc

File tree

3 files changed

+88
-31
lines changed

3 files changed

+88
-31
lines changed

linux/utils/check_guest_os_gui.yml

+75-25
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,83 @@
11
# Copyright 2021-2024 VMware, Inc.
22
# SPDX-License-Identifier: BSD-2-Clause
33
---
4-
# Check whether guest OS has desktop environment and
5-
# get display manager if deskotp environment is installed
6-
- name: "Initialize facts of guest OS having desktop environment and display manager"
4+
# Check whether guest OS has desktop environment
5+
# If desktop environment is running, get display manager and session type
6+
- name: "Initialize facts about guest OS desktop environment"
77
ansible.builtin.set_fact:
88
guest_os_with_gui: false
99
guest_os_display_manager: ""
10+
guest_os_session_type: "tty"
11+
guest_os_session_desktop: ""
1012

1113
- name: "Check Linux guest OS has desktop environment or not"
1214
when: guest_os_ansible_system == "linux"
1315
block:
14-
- name: "Get guest OS display manager service detail"
15-
ansible.builtin.shell: "systemctl status display-manager.service"
16-
register: display_manager_status
17-
changed_when: false
18-
ignore_errors: true
16+
- name: "List all login sessions in guest OS"
17+
ansible.builtin.shell: "loginctl --no-legend list-sessions | awk '{print $1}'"
1918
delegate_to: "{{ vm_guest_ip }}"
19+
register: list_login_sessions
20+
ignore_errors: true
2021

21-
- name: "Set facts of guest OS desktop environment for {{ guest_os_ansible_distribution }}"
22-
ansible.builtin.set_fact:
23-
guest_os_with_gui: true
24-
guest_os_display_manager: |-
25-
{%- if "GNOME Display Manager" in display_manager_status.stdout_lines[0] -%}gdm
26-
{%- elif "Light Display Manager" in display_manager_status.stdout_lines[0] -%}lightdm
27-
{%- elif "X Display Manager" in display_manager_status.stdout_lines[0] -%}xdm
28-
{%- elif "LXDE Display Manager" in display_manager_status.stdout_lines[0] -%}lxdm
29-
{%- elif "Simple Desktop Display Manager" in display_manager_status.stdout_lines[0] -%}sddm
30-
{%- elif guest_os_ansible_distribution == 'Astra Linux (Orel)' -%}fly-dm
31-
{%- endif -%}
22+
- name: "Get desktop session from login sessions"
3223
when:
33-
- display_manager_status.rc is defined
34-
- display_manager_status.rc == 0
35-
- display_manager_status.stdout_lines is defined
36-
- display_manager_status.stdout_lines | length > 0
24+
- list_login_sessions.rc is defined
25+
- list_login_sessions.rc == 0
26+
- list_login_sessions.stdout_lines is defined
27+
- list_login_sessions.stdout_lines | length > 0
28+
block:
29+
- name: "Get types of all login sessions"
30+
ansible.builtin.shell: "loginctl -p Type -p Desktop show-session {{ session_id }}"
31+
delegate_to: "{{ vm_guest_ip }}"
32+
register: get_session_types
33+
ignore_errors: true
34+
with_items: "{{ list_login_sessions.stdout_lines }}"
35+
loop_control:
36+
loop_var: session_id
37+
38+
- name: "Set fact of all login session types"
39+
ansible.builtin.set_fact:
40+
guest_login_sessions: >-
41+
{{
42+
get_session_types.results |
43+
selectattr('stdout', 'defined') |
44+
map(attribute='stdout') |
45+
map('replace', '=', ': ') |
46+
map('from_yaml') |
47+
select('search', 'x11|wayland', ignorecase=true)
48+
}}
49+
50+
- name: "Get display manager, session type and desktop in guest OS"
51+
when: guest_login_sessions | length > 0
52+
block:
53+
- name: "Set facts of desktop environment and session type in guest OS"
54+
ansible.builtin.set_fact:
55+
guest_os_with_gui: true
56+
guest_os_session_type: "{{ guest_login_sessions[0].Type }}"
57+
guest_os_session_desktop: "{{ guest_login_sessions[0].Desktop }}"
58+
59+
- name: "Get guest OS display manager service detail"
60+
ansible.builtin.shell: "systemctl status display-manager.service"
61+
register: display_manager_status
62+
changed_when: false
63+
ignore_errors: true
64+
delegate_to: "{{ vm_guest_ip }}"
65+
66+
- name: "Set fact of display manager in guest OS"
67+
ansible.builtin.set_fact:
68+
guest_os_display_manager: |-
69+
{%- if "GNOME Display Manager" in display_manager_status.stdout_lines[0] -%}gdm
70+
{%- elif "Light Display Manager" in display_manager_status.stdout_lines[0] -%}lightdm
71+
{%- elif "X Display Manager" in display_manager_status.stdout_lines[0] -%}xdm
72+
{%- elif "LXDE Display Manager" in display_manager_status.stdout_lines[0] -%}lxdm
73+
{%- elif "Simple Desktop Display Manager" in display_manager_status.stdout_lines[0] -%}sddm
74+
{%- elif guest_os_ansible_distribution == 'Astra Linux (Orel)' -%}fly-dm
75+
{%- endif -%}
76+
when:
77+
- display_manager_status.rc is defined
78+
- display_manager_status.rc == 0
79+
- display_manager_status.stdout_lines is defined
80+
- display_manager_status.stdout_lines | length > 0
3781

3882
- name: "Check FreeBSD has desktop environment or not"
3983
when: guest_os_ansible_system == "freebsd"
@@ -48,12 +92,16 @@
4892
when:
4993
- pgrep_result.rc is defined
5094
- pgrep_result.rc == 0
51-
- pgrep_result.stdout_lines is defined
52-
- pgrep_result.stdout_lines | length > 0
95+
- pgrep_result.stdout is defined
96+
- pgrep_result.stdout
5397
block:
5498
- name: "Set fact of guest OS having desktop environment"
5599
ansible.builtin.set_fact:
56100
guest_os_with_gui: true
101+
guest_os_session_type: |-
102+
{%- if 'Xorg' in pgrep_result.stdout -%}x11
103+
{%- elif 'Xwayland' in pgrep_result.stdout -%}wayland
104+
{%- endif -%}
57105
58106
- name: "Check display manager on {{ vm_guest_os_distribution }}"
59107
ansible.builtin.shell: "grep -io -E '^(gdm|slim|lightdm|sddm|xdm)_enable=.*YES' /etc/rc.conf"
@@ -75,3 +123,5 @@
75123
msg:
76124
- "Guest OS has desktop environment: {{ guest_os_with_gui }}"
77125
- "Guest OS display manager: {{ guest_os_display_manager }}"
126+
- "Guest OS session type: {{ guest_os_session_type }}"
127+
- "Guest OS session desktop: {{ guest_os_session_desktop }}"

linux/utils/get_linux_system_info.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@
125125
ansible.builtin.debug:
126126
msg:
127127
- "Guest OS: {{ guest_os_ansible_distribution }}"
128-
- "Guest OS type: {{ guest_os_ansible_system }}"
129-
- "Guest OS arch: {{ guest_os_ansible_architecture }}"
130-
- "Guest OS bit: {{ guest_os_bit }}"
128+
- "Guest OS edition: {{ guest_os_edition }}"
129+
- "Guest OS version: {{ guest_os_ansible_distribution_ver }}"
131130
- "Guest OS major version: {{ guest_os_ansible_distribution_major_ver }}"
132131
- "Guest OS minor version: {{ guest_os_ansible_distribution_minor_ver }}"
133-
- "Guest OS version: {{ guest_os_ansible_distribution_ver }}"
134-
- "Guest OS kernel: {{ guest_os_ansible_kernel }}"
132+
- "Guest OS arch: {{ guest_os_ansible_architecture }}"
133+
- "Guest OS bit: {{ guest_os_bit }}"
135134
- "Guest OS release: {{ guest_os_ansible_distribution_release }}"
136-
- "Guest OS edition: {{ guest_os_edition }}"
137135
- "Guest OS family: {{ guest_os_family }}"
136+
- "Guest OS type: {{ guest_os_ansible_system }}"
137+
- "Guest OS kernel: {{ guest_os_ansible_kernel }}"
138138
- "Guest OS with desktop environment: {{ guest_os_with_gui }}"
139139
- "Guest OS display manager: {{ guest_os_display_manager }}"
140+
- "Guest OS session type: {{ guest_os_session_type }}"
141+
- "Guest OS session desktop: {{ guest_os_session_desktop }}"
140142

141143
- name: "Set fact of VM guest OS type"
142144
ansible.builtin.set_fact:

plugin/ansible_vsphere_gosv_log.py

+5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ def __init__(self, vm_name, ansible_gosv_facts):
263263
self.Guest_OS_Distribution = ansible_gosv_facts.get('vm_guest_os_distribution', '')
264264
self.IP = ansible_gosv_facts.get('vm_guest_ip', '')
265265
self.GUI_Installed = str(ansible_gosv_facts.get('guest_os_with_gui', ''))
266+
if self.GUI_Installed == 'True':
267+
display_manager = ansible_gosv_facts.get('guest_os_display_manager', '').upper()
268+
session_type = ansible_gosv_facts.get('guest_os_session_type', '')
269+
if display_manager and session_type:
270+
self.GUI_Installed = f"{self.GUI_Installed} ({display_manager} {session_type})"
266271
self.CloudInit_Version = ansible_gosv_facts.get('cloudinit_version', '')
267272
super().__init__(ansible_gosv_facts)
268273

0 commit comments

Comments
 (0)