Skip to content

Commit eb3457d

Browse files
author
Derek
committed
fix: Re-detect GNOME after desktop.yml installs it
For Packer headless builds, init.yml runs before desktop.yml installs GNOME, so has_gnome was always false. This caused all desktop-related tasks (Nemo, VS Code, Chrome, Brave, extensions, avatar) to be skipped. Changes: - main.yml: Re-check for /usr/bin/gnome-shell after desktop.yml runs - main.yml: Install psutil for dconf after GNOME detection - main.yml: Include avatar.yml after GNOME is confirmed installed - avatar.yml: New file with avatar deployment tasks (moved from init.yml) - init.yml: Remove avatar tasks (now in avatar.yml) This ensures desktop customizations work on fresh Packer builds where GNOME is installed during the build, not pre-existing in the base image.
1 parent 3425010 commit eb3457d

3 files changed

Lines changed: 143 additions & 86 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
# Avatar deployment for GDM login screen
3+
# Separated from init.yml so it can run after desktop.yml installs GNOME
4+
#
5+
# Deploys custom avatar for:
6+
# - Current user: /var/lib/AccountsService/icons/<username>
7+
# - System default: /usr/share/pixmaps/faces/default-user.png
8+
#
9+
# Controlled by branding_enabled and avatar_file variables
10+
11+
- name: Deploy user avatar for current user
12+
ansible.builtin.copy:
13+
src: "{{ avatar_file }}"
14+
dest: "/var/lib/AccountsService/icons/{{ actual_user }}"
15+
mode: '0644'
16+
when:
17+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
18+
- has_gnome | default(false)
19+
- branding_enabled | default(true)
20+
- avatar_file | default('') | length > 0
21+
22+
- name: Configure AccountsService to use custom avatar for current user
23+
ansible.builtin.lineinfile:
24+
path: "/var/lib/AccountsService/users/{{ actual_user }}"
25+
regexp: '^Icon='
26+
line: "Icon=/var/lib/AccountsService/icons/{{ actual_user }}"
27+
create: true
28+
mode: '0600'
29+
when:
30+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
31+
- has_gnome | default(false)
32+
- branding_enabled | default(true)
33+
- avatar_file | default('') | length > 0
34+
35+
# Set as system-wide default for new users
36+
- name: Ensure faces directory exists for default avatars
37+
ansible.builtin.file:
38+
path: /usr/share/pixmaps/faces
39+
state: directory
40+
mode: '0755'
41+
when:
42+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
43+
- has_gnome | default(false)
44+
- branding_enabled | default(true)
45+
- avatar_file | default('') | length > 0
46+
47+
- name: Deploy avatar as system default for new users
48+
ansible.builtin.copy:
49+
src: "{{ avatar_file }}"
50+
dest: /usr/share/pixmaps/faces/default-user.png
51+
mode: '0644'
52+
when:
53+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
54+
- has_gnome | default(false)
55+
- branding_enabled | default(true)
56+
- avatar_file | default('') | length > 0
57+
58+
- name: Ensure dconf database directory exists
59+
ansible.builtin.file:
60+
path: /etc/dconf/db/local.d
61+
state: directory
62+
mode: '0755'
63+
when:
64+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
65+
- has_gnome | default(false)
66+
- branding_enabled | default(true)
67+
- avatar_file | default('') | length > 0
68+
69+
- name: Configure AccountsService default icon path
70+
ansible.builtin.copy:
71+
dest: /etc/dconf/db/local.d/01-default-avatar
72+
content: |
73+
[org/gnome/login-screen]
74+
logo='/usr/share/pixmaps/faces/default-user.png'
75+
mode: '0644'
76+
register: default_avatar_dconf
77+
when:
78+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
79+
- has_gnome | default(false)
80+
- branding_enabled | default(true)
81+
- avatar_file | default('') | length > 0
82+
83+
- name: Update dconf database for default avatar
84+
ansible.builtin.command:
85+
cmd: dconf update
86+
changed_when: true
87+
when:
88+
- default_avatar_dconf.changed | default(false)

ansible/roles/developer/tasks/init.yml

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -114,89 +114,5 @@
114114
- ansible_facts['distribution'] == 'Ubuntu'
115115
- has_gnome | default(false)
116116

117-
# ============================================================================
118-
# USER AVATAR (GDM login screen)
119-
# ============================================================================
120-
# Deploy custom avatar for GDM login screen and set as system default
121-
# - Current user: /var/lib/AccountsService/icons/<username>
122-
# - System default: /usr/share/pixmaps/faces/default-user.png
123-
# Controlled by branding_enabled and avatar_file variables
124-
125-
- name: Deploy user avatar for current user
126-
ansible.builtin.copy:
127-
src: "{{ avatar_file }}"
128-
dest: "/var/lib/AccountsService/icons/{{ actual_user }}"
129-
mode: '0644'
130-
when:
131-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
132-
- has_gnome | default(false)
133-
- branding_enabled | default(true)
134-
- avatar_file | default('') | length > 0
135-
136-
- name: Configure AccountsService to use custom avatar for current user
137-
ansible.builtin.lineinfile:
138-
path: "/var/lib/AccountsService/users/{{ actual_user }}"
139-
regexp: '^Icon='
140-
line: "Icon=/var/lib/AccountsService/icons/{{ actual_user }}"
141-
create: true
142-
mode: '0600'
143-
when:
144-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
145-
- has_gnome | default(false)
146-
- branding_enabled | default(true)
147-
- avatar_file | default('') | length > 0
148-
149-
# Set as system-wide default for new users
150-
- name: Ensure faces directory exists for default avatars
151-
ansible.builtin.file:
152-
path: /usr/share/pixmaps/faces
153-
state: directory
154-
mode: '0755'
155-
when:
156-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
157-
- has_gnome | default(false)
158-
- branding_enabled | default(true)
159-
- avatar_file | default('') | length > 0
160-
161-
- name: Deploy avatar as system default for new users
162-
ansible.builtin.copy:
163-
src: "{{ avatar_file }}"
164-
dest: /usr/share/pixmaps/faces/default-user.png
165-
mode: '0644'
166-
when:
167-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
168-
- has_gnome | default(false)
169-
- branding_enabled | default(true)
170-
- avatar_file | default('') | length > 0
171-
172-
- name: Ensure dconf database directory exists
173-
ansible.builtin.file:
174-
path: /etc/dconf/db/local.d
175-
state: directory
176-
mode: '0755'
177-
when:
178-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
179-
- has_gnome | default(false)
180-
- branding_enabled | default(true)
181-
- avatar_file | default('') | length > 0
182-
183-
- name: Configure AccountsService default icon path
184-
ansible.builtin.copy:
185-
dest: /etc/dconf/db/local.d/01-default-avatar
186-
content: |
187-
[org/gnome/login-screen]
188-
logo='/usr/share/pixmaps/faces/default-user.png'
189-
mode: '0644'
190-
register: default_avatar_dconf
191-
when:
192-
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
193-
- has_gnome | default(false)
194-
- branding_enabled | default(true)
195-
- avatar_file | default('') | length > 0
196-
197-
- name: Update dconf database for default avatar
198-
ansible.builtin.command:
199-
cmd: dconf update
200-
changed_when: true
201-
when:
202-
- default_avatar_dconf.changed | default(false)
117+
# NOTE: Avatar deployment moved to avatar.yml and called from main.yml
118+
# after desktop.yml installs GNOME (so has_gnome is true)

ansible/roles/developer/tasks/main.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@
1414
tags: ['desktop']
1515
when: ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
1616

17+
# Re-detect GNOME after desktop.yml installs it
18+
# This is critical for Packer headless builds where GNOME wasn't installed at init.yml time
19+
- name: Re-check if GNOME Shell is now installed (after desktop.yml)
20+
ansible.builtin.stat:
21+
path: /usr/bin/gnome-shell
22+
register: gnome_shell_post_desktop
23+
when: ansible_facts['distribution'] != 'MacOSX'
24+
tags: ['desktop']
25+
26+
- name: Update GNOME availability fact after desktop installation
27+
ansible.builtin.set_fact:
28+
has_gnome: "{{ gnome_shell_post_desktop.stat.exists | default(false) }}"
29+
when:
30+
- ansible_facts['distribution'] != 'MacOSX'
31+
- gnome_shell_post_desktop is defined
32+
tags: ['desktop']
33+
34+
- name: Display updated GNOME status
35+
ansible.builtin.debug:
36+
msg: "GNOME desktop (post-install check): {{ 'Installed' if has_gnome else 'Not installed' }}"
37+
tags: ['desktop']
38+
39+
# Install psutil for dconf module (required for GNOME settings tasks)
40+
# This needs to run after GNOME is detected/installed, not in init.yml
41+
- name: Install psutil for dconf module (Fedora - post desktop install)
42+
ansible.builtin.dnf:
43+
name: python3-psutil
44+
state: present
45+
when:
46+
- ansible_facts['distribution'] == 'Fedora'
47+
- has_gnome | default(false)
48+
tags: ['desktop']
49+
50+
- name: Install psutil for dconf module (Ubuntu - post desktop install)
51+
ansible.builtin.apt:
52+
name: python3-psutil
53+
state: present
54+
when:
55+
- ansible_facts['distribution'] == 'Ubuntu'
56+
- has_gnome | default(false)
57+
tags: ['desktop']
58+
59+
# Deploy avatar after GNOME is installed (moved from init.yml)
60+
- name: Deploy user avatar for GDM login screen
61+
ansible.builtin.include_tasks:
62+
file: avatar.yml
63+
apply:
64+
tags: ['desktop', 'avatar']
65+
tags: ['desktop', 'avatar']
66+
when:
67+
- ansible_facts['distribution'] in ['Fedora', 'Ubuntu']
68+
- has_gnome | default(false)
69+
1770
- name: Install Nemo file manager (replaces Nautilus as default)
1871
ansible.builtin.include_tasks:
1972
file: nemo.yml

0 commit comments

Comments
 (0)