-
Notifications
You must be signed in to change notification settings - Fork 6
/
fedora_init.yml
642 lines (586 loc) · 16.7 KB
/
fedora_init.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# Usage:
# 1) Copy the accompanying ansible.cfg as ~/.ansible.cfg
# 2) Install Ansible
# 3) Adjust and run the playbook
# 4) Set password for the new user and reboot
---
- name: Initialize Fedora
hosts: all
become: true
gather_facts: true
vars:
console_keymap: fi
console_font: eurlatgr
langpacks: ['en', 'fi']
system_locale: C.UTF-8
system_timezone: Europe/Helsinki
root_shell: /bin/zsh
create_user: false
user_uid: 1000
user_name: mm
user_group: users
user_shell: /bin/zsh
workstation: false
enable_sshd: true
disable_network_services: true
tasks:
- name: Check target basics
check_mode: false
raw: rpm -q python3 python3-libdnf5 python3-libselinux
register: basics
failed_when: false
changed_when: false
- name: Prepare target basics
raw: dnf -y install python3 python3-libdnf5 python3-libselinux
changed_when: true
when: basics.rc != 0
- name: Create target remote_tmp
file:
path: "{{ ansible_facts.env.HOME }}/.ansible/tmp"
state: directory
mode: '0700'
- name: Detect boot parameters
check_mode: false
command: grep -q TIMEOUT=5 /etc/default/grub
register: adjust_boot_parameters
failed_when: false
changed_when: false
- name: Install grubby
dnf:
name: grubby
state: present
when: adjust_boot_parameters.rc == 0
- name: Adjust boot timeout
replace:
dest: /etc/default/grub
regexp: '^GRUB_TIMEOUT=.*'
replace: 'GRUB_TIMEOUT=1'
when: adjust_boot_parameters.rc == 0
- name: Adjust boot parameters
command: grubby --remove-args="rhgb" --args="quiet" --update-kernel=ALL
changed_when: true
when: adjust_boot_parameters.rc == 0
- name: Detect rescue images
find:
paths:
- /boot
- /boot/loader/entries
patterns:
- '*rescue*'
register: rescue_images
- name: Remove rescue images
file:
path: "{{ item }}"
state: absent
loop: "{{ rescue_images.files | map(attribute='path') }}"
- name: Update GRUB configuration
command: grub2-mkconfig -o /boot/grub2/grub.cfg
changed_when: true
when: adjust_boot_parameters.rc == 0
- name: Detect LUKS configuration
check_mode: false
command: grep -q mapper/luks /etc/fstab
register: luks_in_use
failed_when: false
changed_when: false
- name: Configure console
copy:
content: |
KEYMAP="{{ console_keymap }}"
FONT="{{ console_font }}"
dest: /etc/vconsole.conf
mode: '0644'
- name: Configure locale
copy:
content: |
LANG="{{ system_locale }}"
dest: /etc/locale.conf
mode: '0644'
- name: Set timezone
community.general.timezone:
name: "{{ system_timezone }}"
- name: Check RPM Fusion repository
# noqa: command-instead-of-module
command: >
rpm -q rpmfusion-free-release-{{ ansible_facts.distribution_major_version }} rpmfusion-nonfree-release-{{ ansible_facts.distribution_major_version }}
register: fusion_enabled
failed_when: false
changed_when: false
when: workstation | bool
- name: Enable RPM Fusion repository
dnf:
name:
- https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ ansible_facts.distribution_major_version }}.noarch.rpm
- https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{{ ansible_facts.distribution_major_version }}.noarch.rpm
state: present
disable_gpg_check: true
when: workstation | bool and fusion_enabled.rc != 0
- name: Remove unneeded firmware packages
dnf:
name:
- 'a*firmware*'
- 'i*firmware*'
- 'lib*firmware*'
- linux-firmware
- 'n*firmware*'
- 'z*firmware'
state: absent
cacheonly: true
disablerepo: '*'
when: ansible_facts.virtualization_role == "guest"
- name: Remove all virtual guest packages
dnf:
name:
- 'hyperv*'
- open-vm-tools
- qemu-guest-agent
- spice-vdagent
- virtualbox-guest-additions
- WALinuxAgent
state: absent
cacheonly: true
disablerepo: '*'
when: ansible_facts.virtualization_role != "guest"
- name: Remove unhelpful packages on VM
dnf:
name:
- akmods
- 'dmraid*'
#- 'libvirt*'
- 'pcsc*'
- thermald
state: absent
cacheonly: true
disablerepo: '*'
when: ansible_facts.virtualization_role == "guest"
- name: Remove unneeded packages on Azure/Hyper-V
dnf:
name:
- open-vm-tools
- qemu-guest-agent
- spice-vdagent
- virtualbox-guest-additions
state: absent
cacheonly: true
disablerepo: '*'
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type == "VirtualPC"
- name: Remove unneeded packages on KVM
dnf:
name:
- 'hyperv*'
- open-vm-tools
- virtualbox-guest-additions
- WALinuxAgent
state: absent
cacheonly: true
disablerepo: '*'
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type == "kvm"
- name: Remove unneeded packages on VirtualBox
dnf:
name:
- 'hyperv*'
- open-vm-tools
- qemu-guest-agent
- spice-vdagent
- WALinuxAgent
state: absent
cacheonly: true
disablerepo: '*'
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type == "virtualbox"
- name: Remove unneeded packages on VMware
dnf:
name:
- 'hyperv*'
- qemu-guest-agent
- spice-vdagent
- virtualbox-guest-additions
- WALinuxAgent
state: absent
cacheonly: true
disablerepo: '*'
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type == "VMware"
- name: Remove unneeded packages on other VMs
dnf:
name:
- 'hyperv*'
- open-vm-tools
- qemu-guest-agent
- spice-vdagent
- virtualbox-guest-additions
- WALinuxAgent
state: absent
cacheonly: true
disablerepo: '*'
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type not in ['kvm', 'virtualbox', 'VirtualPC', 'VMware']
- name: Remove unneeded Plymouth packages
dnf:
name:
- 'plymouth*'
state: absent
cacheonly: true
disablerepo: '*'
when: not luks_in_use.rc == 0
- name: Remove unhelpful packages
dnf:
name:
- NetworkManager-adsl
- NetworkManager-openconnect
- NetworkManager-pptp
- NetworkManager-team
- NetworkManager-tui
#- 'PackageKit*'
- 'abrt*'
- anaconda
- 'b43*'
- cifs-utils
- cockpit
- dracut-config-rescue
- dracut-live
- evolution
- 'foomatic*'
- gnome-tour
- gnome-user-docs
- 'gutenprint*'
- '*hangul*'
- 'hplip*'
- 'java*'
- kernel-modules-extra
- kexec-tools
- '*kkc*'
- '*libreoffice*'
- mediawriter
- nfs-utils
- orca
- pam_krb5
#- 'perl*'
- '*pinyin*'
- qgnomeplatform
#- 'qt*'
- realmd
- 'sane*'
- teamd
- trousers
- '*zhuyin*'
state: absent
autoremove: true
cacheonly: true
disablerepo: '*'
- name: Install helpful packages (common)
dnf:
name:
- bash-completion
- bc
- bind-utils
- ethtool
- git-core
- glibc-minimal-langpack
#- gpm
#- iotop
- irqbalance
- keychain
#- ltrace
- man-pages
- nano
#- nmap-ncat
#- numactl
- openssh-clients
#- pcp-doc
#- pcp-system-tools
#- perf
- plocate
- policycoreutils-python-utils
- psmisc
- setools-console
- strace
- tar
- tcpdump
#- telnet
- tmux
- tuned
- unzip
- util-linux-user
- yum-utils
- zsh
- zstd
state: present
- name: Install helpful packages (guest agent)
vars:
agent_packages:
kvm: qemu-guest-agent
virtualbox: virtualbox-guest-additions
VirtualPC:
- hyperv-daemons
- WALinuxAgent
VMware: open-vm-tools
dnf:
name: "{{ agent_packages[ansible_facts.virtualization_type] }}"
state: present
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type in agent_packages
- name: Enable virtual guest agent service
vars:
agent_services:
kvm: qemu-guest-agent.service
virtualbox: vboxservice.service
VirtualPC: waagent.service
VMware: vmtoolsd.service
service:
name: "{{ agent_services[ansible_facts.virtualization_type] }}"
state: started
enabled: true
when:
- ansible_facts.virtualization_role == "guest"
- ansible_facts.virtualization_type in agent_services
- ansible_facts.virtualization_type in ['kvm', 'virtualbox', 'VirtualPC', 'VMware']
- name: Install helpful packages (langpacks)
dnf:
name: glibc-langpack-{{ langpacks | join(',glibc-langpack-') }}
state: present
- name: Install helpful packages (workstation)
dnf:
name:
- GraphicsMagick
- dconf-editor
- ffmpeg
#- fuse-sshfs
- gnome-tweaks
- gstreamer1-libav
- gstreamer1-plugins-good-gtk
- libavc1394
- ntfsprogs
- patch
#- powertop
- seahorse
- totem
#- vlc
- xauth
- xclip
- xorg-x11-fonts-misc
- xorriso
- youtube-dl
state: present
when: workstation | bool
- name: Install helpful packages (workstation langpacks)
dnf:
name: langpacks-core-{{ langpacks | join(',langpacks-') }}
state: present
when: workstation | bool
- name: Remove unhelpful packages ('all' langpacks)
dnf:
name:
- gawk-all-langpacks
- glibc-all-langpacks
state: absent
cacheonly: true
disablerepo: '*'
- name: Update all packages
# noqa: package-latest
dnf:
name: '*'
state: latest
update_cache: true
- name: Check current boot parameters
check_mode: false
shell: set -o pipefail ; cat /proc/cmdline | grep -q rhgb
register: rhgb_used
failed_when: false
changed_when: false
- name: Ensure correct boot parameters
command: grubby --remove-args="rhgb" --args="quiet" --update-kernel=ALL
changed_when: true
when: rhgb_used.rc == 0
- name: Disable unhelpful services
service:
name: "{{ item }}"
enabled: false
loop:
- cups.service
- dmraid-activation.service
- dnf-makecache.timer
- lvm2-monitor.service
- mcelog.service
- mdmonitor.service
- multipathd.service
#- pmie.service
failed_when: false
- name: Disable unhelpful services on VMs
service:
name: "{{ item }}"
enabled: false
loop:
- raid-check.timer
- switcheroo-control
- upower.service
failed_when: false
when: ansible_facts.virtualization_role == "guest"
- name: Disable unhelpful network services
service:
name: "{{ item }}"
enabled: false
loop:
- bluetooth.service
- iscsi.service
- iscsid.socket
- iscsiuio.socket
- nfs-client.target
- nfs-convert.service
- remote-fs.target
- sssd.service
failed_when: false
when: disable_network_services | bool
- name: Enable helpful services
service:
name: "{{ item }}"
enabled: true
loop:
#- gpm.service
- irqbalance.service
#- pmcd.service
#- pmlogger.service
- tuned.service
- name: Install SSH daemon
dnf:
name: openssh-server
state: present
when: enable_sshd | bool
- name: Enable SSH daemon
service:
name: sshd
state: started
enabled: true
when: enable_sshd | bool
- name: Change root shell
user:
name: root
shell: "{{ root_shell }}"
- name: Disable pulseaudio for root, part I
file:
path: /root/.config/systemd/user
state: directory
mode: '0755'
- name: Disable pulseaudio for root, part II
file:
state: link
src: /dev/null
dest: /root/.config/systemd/user/{{ item }}
loop:
- pulseaudio.service
- pulseaudio.socket
- name: Create user, part I
user:
name: "{{ user_name }}"
uid: "{{ user_uid }}"
group: "{{ user_group }}"
shell: "{{ user_shell }}"
when: create_user | bool
- name: Create user, part II
copy:
content: |
[User]
Language=
XSession=
Icon=/home/{{ user_name }}/.face
SystemAccount=false
dest: /var/lib/AccountsService/users/{{ user_name }}
owner: root
group: root
mode: '0600'
when: workstation | bool and create_user | bool
- name: Disable tracker for the user, part I
file:
path: /home/{{ user_name }}/.config/systemd/user
state: directory
owner: "{{ user_name }}"
group: "{{ user_group }}"
mode: '0755'
when: false and create_user | bool
- name: Disable tracker for the user, part II
file:
state: link
src: /dev/null
dest: /home/{{ user_name }}/.config/systemd/user/{{ item }}
owner: "{{ user_name }}"
group: "{{ user_group }}"
loop:
- tracker-extract.service
- tracker-miner-apps.service
- tracker-miner-fs.service
- tracker-miner-rss.service
- tracker-store.service
- tracker-writeback.service
when: false and create_user | bool
- name: Disable tracker for the user, part III
command: restorecon -Rv "/home/{{ user_name }}/.config/systemd"
register: restorecon
changed_when: "'Relabeled' in restorecon.stdout"
when: false and create_user | bool
- name: Configure sudoers
lineinfile:
path: /etc/sudoers.d/{{ user_name }}
line: '{{ user_name }} ALL=(ALL) NOPASSWD: ALL'
create: true
mode: '0440'
validate: /usr/sbin/visudo -csf %s
when: create_user | bool
- name: Create Windows partition mount point
file:
path: /mnt/c
state: directory
mode: '0755'
when: workstation | bool
- name: Check Windows mount point configuration
check_mode: true
lineinfile:
path: /etc/fstab
regexp: '.* ntfs .*'
line: ''
register: ntfs_line
changed_when: false
when: workstation | bool
# Needs to be adjusted and enabled manually
- name: Create Windows mount point fstab entry
lineinfile:
path: /etc/fstab
line: "#/dev/sda5 /mnt/c ntfs noauto,ro,uid={{ user_uid }},nls=utf8,comment=systemd.automount 1 2"
when: workstation | bool and ntfs_line.msg == "line added"
- name: Clean up, part I
file:
path: "{{ item }}"
state: absent
loop:
- /1
- /etc/rc.d/init.d/livesys
- /root/.config/pulse
- /root/.esd_auth
- /root/.lesshst
- /root/.local/share/ibus-typing-booster
- /root/.rnd
- /root/.wget-hsts
- /root/anaconda-ks.cfg
- /root/original-ks.cfg
- /var/lib/abrt
- /var/spool/abrt
- /var/tmp/abrt
- name: Clean up, part II
find:
paths:
- /tmp
patterns:
- 'ks-script*'
register: tmp_files
- name: Clean up, part III
file:
path: "{{ item }}"
state: absent
loop: "{{ tmp_files.files | map(attribute='path') }}"