Skip to content

Commit a95e6e7

Browse files
author
Derek
committed
feat: add --force-gnome flag for headless template builds
When building VM templates via Packer, GNOME is installed but not running (no active session). The previous pgrep gnome-shell check caused all GNOME customizations to be skipped. Changes: - Add dfe_force_gnome variable (default: false) to defaults/main.yml - Modify init.yml to skip pgrep check when dfe_force_gnome=true - Add --force-gnome flag to install.sh that passes -e dfe_force_gnome=true Usage for template builds: ./install.sh --all --force-gnome
1 parent 7c26e8a commit a95e6e7

3 files changed

Lines changed: 41 additions & 5 deletions

File tree

ansible/roles/dfe_developer/defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
# All options are now controlled via tags, not variables.
44
# Use --skip-tags to disable features, --tags to enable optional ones.
55

6+
# GNOME detection override for headless/template builds
7+
# When true, skips the 'pgrep gnome-shell' check and assumes GNOME is available.
8+
# Use this for Packer template builds where GNOME is installed but not running.
9+
# Example: ansible-playbook ... -e "dfe_force_gnome=true"
10+
dfe_force_gnome: false
11+
612
# Supported platforms (used for validation in init.yml)
713
dfe_supported_distros:
814
- Fedora

ansible/roles/dfe_developer/tasks/init.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,32 @@
8181
register: gnome_running_check
8282
failed_when: false
8383
changed_when: false
84-
when: ansible_distribution != 'MacOSX'
84+
when:
85+
- ansible_distribution != 'MacOSX'
86+
- not (dfe_force_gnome | default(false))
8587

86-
- name: Set GNOME availability fact (Linux)
88+
- name: Check if GNOME Shell is installed (fallback for headless/template builds)
89+
ansible.builtin.stat:
90+
path: /usr/bin/gnome-shell
91+
register: gnome_shell_installed
92+
when:
93+
- ansible_distribution != 'MacOSX'
94+
- not (dfe_force_gnome | default(false))
95+
96+
- name: Set GNOME availability fact (Linux - running session)
8797
ansible.builtin.set_fact:
8898
dfe_has_gnome: "{{ gnome_running_check.rc == 0 }}"
89-
when: ansible_distribution != 'MacOSX'
99+
when:
100+
- ansible_distribution != 'MacOSX'
101+
- not (dfe_force_gnome | default(false))
102+
- gnome_running_check is defined
103+
104+
- name: Set GNOME availability fact (Linux - forced for headless/template builds)
105+
ansible.builtin.set_fact:
106+
dfe_has_gnome: true
107+
when:
108+
- ansible_distribution != 'MacOSX'
109+
- dfe_force_gnome | default(false)
90110

91111
- name: Set GNOME availability fact (macOS - N/A)
92112
ansible.builtin.set_fact:

install.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ OPTIONS:
5656
--branch BRANCH Git branch to use (default: main)
5757
--core Shortcut for: --tags developer,base,core,advanced
5858
--all Shortcut for: --tags developer,base,core,advanced,vm,optimizer,rdp,winlike
59+
--force-gnome Force GNOME configuration even if no GNOME session is running
60+
(for headless/template builds where GNOME is installed but inactive)
5961
--help Show this help message
6062
6163
AVAILABLE TAGS:
@@ -123,6 +125,7 @@ EOF
123125
ANSIBLE_CHECK=""
124126
ANSIBLE_TAGS=""
125127
ANSIBLE_SKIP_TAGS=""
128+
ANSIBLE_EXTRA_VARS=""
126129
GIT_BRANCH="main"
127130

128131
while [[ $# -gt 0 ]]; do
@@ -161,6 +164,12 @@ while [[ $# -gt 0 ]]; do
161164
ANSIBLE_TAGS="--tags developer,base,core,advanced,vm,optimizer,rdp,winlike"
162165
shift
163166
;;
167+
--force-gnome)
168+
# Force GNOME configuration even if gnome-shell isn't running
169+
# Useful for headless/template builds where GNOME is installed but not active
170+
ANSIBLE_EXTRA_VARS="-e dfe_force_gnome=true"
171+
shift
172+
;;
164173
--help|-h)
165174
show_help
166175
;;
@@ -330,7 +339,7 @@ fi
330339

331340
# Run Ansible playbook using temp venv Ansible
332341
print_info "Running Ansible playbook (using isolated venv Ansible)..."
333-
print_info "Command: $ANSIBLE_BIN playbooks/main.yml -i inventories/localhost/inventory.yml $ANSIBLE_CHECK $ANSIBLE_TAGS $ANSIBLE_SKIP_TAGS_ARG"
342+
print_info "Command: $ANSIBLE_BIN playbooks/main.yml -i inventories/localhost/inventory.yml $ANSIBLE_CHECK $ANSIBLE_TAGS $ANSIBLE_SKIP_TAGS_ARG $ANSIBLE_EXTRA_VARS"
334343

335344
cd ansible || exit 1
336345

@@ -340,7 +349,8 @@ cd ansible || exit 1
340349
-i inventories/localhost/inventory.yml \
341350
$ANSIBLE_CHECK \
342351
$ANSIBLE_TAGS \
343-
$ANSIBLE_SKIP_TAGS_ARG || {
352+
$ANSIBLE_SKIP_TAGS_ARG \
353+
$ANSIBLE_EXTRA_VARS || {
344354
print_error "Ansible playbook failed"
345355
exit 1
346356
}

0 commit comments

Comments
 (0)