I have already started blogging about Ansible; in particular, I have shown how to develop and test an Ansible role with Molecule and Docker, also on Gitpod. I have also shown my Ansible role for GNOME.
This blog post will describe my Ansible role for installing the KDE Plasma desktop environment with several programs and configurations. As for the other roles I’ve blogged about, this one is tested with Molecule and Docker and can be developed with Gitpod (see the linked posts above). In particular, it is tested in Arch, Ubuntu, and Fedora.
This role is for my personal installation and configuration and is not meant to be reusable.
The role can be found here: https://github.com/LorenzoBettini/my_kde_role.
The role assumes that at least the basic KDE DE is already installed in the Linux distribution. The role then installs several programs I’m using daily and performs a few configurations (it also installs a few extensions I use).
At the time of writing, the role has the following directory structure, which is standard for Ansible roles tested with Molecule.
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 |
├── defaults │ └── main.yml ├── files │ ├── kde-ssh │ │ ├── askpass.sh │ │ ├── ssh-add.desktop │ │ ├── ssh-agent-shutdown.sh │ │ └── ssh-agent-startup.sh │ └── konsole │ ├── AplumaDark.colorscheme │ ├── Apricot.colorscheme │ ├── Apricot.profile │ ├── Aritim Dark.colorscheme │ ├── Aritim Dark.profile │ ├── BlackOnWhite.profile │ ├── Edna.colorscheme │ ├── Edna.profile │ ├── GreenOnBlack.profile │ ├── Nordic.colorscheme │ ├── Nordic.profile │ └── XeroLinux.profile ├── handlers │ └── main.yml ├── LICENSE ├── meta │ └── main.yml ├── molecule │ ├── default │ │ ├── molecule.yml │ │ └── prepare.yml │ ├── fedora │ │ └── molecule.yml │ ├── shared │ │ ├── converge.yml │ │ └── verify.yml │ └── ubuntu │ ├── molecule.yml │ └── prepare.yml ├── pip │ └── requirements.txt ├── README.md ├── requirements.yml ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml |
The role has a few requirements, listed in “requirements.yml”:
1 2 3 |
--- collections: - name: community.general |
These requirements must also be present in playbooks using this role; my playbooks (which I’ll write about in future articles) have such dependencies in the requirements.
Let’s have a look at the main file “tasks/main.yml”, which is quite long, so I’ll show its parts and comment on the relevant parts gradually.
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 |
--- # tasks file for my_kde_role - name: System details ansible.builtin.debug: msg: "{{ item }}" with_items: - "ansible_os_family: {{ ansible_os_family }}" - "ansible_distribution: {{ ansible_distribution }}" - "ansible_distribution_release: {{ ansible_distribution_release }}" - "ansible_distribution_version: {{ ansible_distribution_version }}" - "ansible_distribution_major_version: {{ ansible_distribution_major_version }}" - name: Override spectacle package name for Ubuntu. ansible.builtin.set_fact: kde_spectacle: kde-spectacle when: ansible_os_family == 'Debian' - name: Override kvantum package name for Ubuntu. ansible.builtin.set_fact: kvantum: qt5-style-kvantum when: ansible_os_family == 'Debian' - name: Install Kde Packages become: true ansible.builtin.package: state: present name: - kate - "{{ kde_spectacle }}" - ark - konsole - dolphin - okular - gwenview - yakuake - korganizer - kaddressbook - kdepim-addons - kio-gdrive - dolphin-plugins - plasma-systemmonitor - kcalc - plasma-workspace-wallpapers - "{{ kvantum }}" # - latte-dock # it's not maintained anymore # In Ubuntu doesn't seem to be there # maybe it's not needed - name: Install Kde Addons become: true ansible.builtin.package: state: present name: - kdeplasma-addons when: ansible_os_family != 'Debian' |
This shows a few debugging details about the current Linux distribution. Indeed, the whole role has conditional tasks and variables depending on the current Linux distribution.
The file installs a few KDE programs I’m using in KDE.
The “vars/main.yml” only defines a few default variables used above:
1 2 3 4 |
--- # vars file for my_kde_role kde_spectacle: spectacle kvantum: kvantum |
As seen above, a few packages have a different name in Ubuntu (Debian), which is overridden.
Then, I configure a few things in the KDE configuration (.ini) files and set a few keyboard shortcuts. The configuration should be self-explanatory.
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 |
- name: Meta for Expose (Toggle Present Windows) community.general.ini_file: path: ~/.config/kwinrc section: ModifierOnlyShortcuts option: Meta value: org.kde.kglobalaccel,/component/kwin,org.kde.kglobalaccel.Component,invokeShortcut,Expose no_extra_spaces: yes mode: 0600 - name: Desktop effects community.general.ini_file: path: ~/.config/kwinrc section: '{{ item.section }}' option: '{{ item.option }}' value: '{{ item.value }}' no_extra_spaces: yes mode: 0600 loop: - section: Plugins option: kwin4_effect_squashEnabled value: 'false' - section: Effect-MagicLamp option: AnimationDuration value: '400' - section: Plugins option: magiclampEnabled value: 'true' - name: Switcher community.general.ini_file: path: ~/.config/kwinrc section: '{{ item.section }}' option: '{{ item.option }}' value: '{{ item.value }}' no_extra_spaces: yes mode: 0600 loop: - section: TabBox option: HighlightWindows value: 'false' - section: TabBox option: LayoutName value: compact - name: Ctrl+Alt+T for Konsole community.general.ini_file: path: ~/.config/kglobalshortcutsrc section: org.kde.konsole.desktop option: '{{ item.option }}' value: '{{ item.value }}' no_extra_spaces: yes mode: 0600 loop: - option: _k_friendly_name value: Konsole - option: _launch value: Ctrl+Alt+T,Ctrl+Alt+T,Konsole - name: Meta+X for ExposeAll (Toggle Present Windows (All desktops)) community.general.ini_file: path: ~/.config/kglobalshortcutsrc section: kwin option: ExposeAll value: Meta+Z\tLaunch (C)\tCtrl+F10,Ctrl+F10\tLaunch (C),Toggle Present Windows (All desktops) no_extra_spaces: yes mode: 0600 - name: Meta+Z for ExposeClass (Toggle Present Windows (Window class)) community.general.ini_file: path: ~/.config/kglobalshortcutsrc section: kwin option: ExposeClass value: Ctrl+F7\tMeta+X,Ctrl+F7,Toggle Present Windows (Window class) no_extra_spaces: yes mode: 0600 - name: Alt+\ (Walk Through Windows of Current Application) community.general.ini_file: path: ~/.config/kglobalshortcutsrc section: kwin option: Walk Through Windows of Current Application value: Alt+\\\\,Alt+`,Walk Through Windows of Current Application no_extra_spaces: yes mode: 0600 |
Then, I ensure Kate is the default editor for textual files (including XML files, which otherwise, would be opened with the default browser); I also configure a few Kate preferences:
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 |
# In Fedora it's not installed by default - name: Ensure xdg-mime is available become: true ansible.builtin.package: state: present name: - xdg-utils when: ansible_os_family == 'RedHat' - name: Ensure xdg mime default application is set ansible.builtin.command: "xdg-mime default {{ item[0].desktop_file }} {{ item[1] }}" changed_when: False with_subelements: - "{{ xdg_mime_defaults }}" - mime_types vars: xdg_mime_defaults: - desktop_file: org.kde.kate.desktop mime_types: - text/plain - text/xml - name: Kate preferences community.general.ini_file: path: ~/.config/katerc section: '{{ item.section }}' option: '{{ item.option }}' value: '{{ item.value }}' no_extra_spaces: yes mode: 0600 loop: - section: KTextEditor Document option: ReplaceTabsDyn value: 'false' - section: KTextEditor Document option: Swap Directory value: /tmp/ - section: KTextEditor Document option: Swap File Mode value: 2 |
Then, I copy a few Konsole profiles (and the corresponding color schemes, see the directory “files/konsole”) and also configure the Yakuake drop-down terminal:
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 |
- name: Create Konsole profile directory ansible.builtin.file: path: '~/.local/share/konsole' mode: 0775 state: directory - name: Copy Konsole profiles ansible.builtin.copy: src: "konsole/" dest: "~/.local/share/konsole/" mode: 0600 - name: Yakuake preferences community.general.ini_file: path: ~/.config/yakuakerc mode: 0600 section: '{{ item.section }}' option: '{{ item.option }}' value: '{{ item.value }}' no_extra_spaces: yes loop: - section: Appearance # https://wiki.archlinux.org/title/Yakuake#Background_transparency_and_blur_on_Plasma option: Blur value: 'true' - section: Appearance option: Translucency value: 'true' - section: Desktop Entry option: DefaultProfile value: Apricot.profile - section: Window option: Height value: 60 |
The final part deals with configuring the Kwallet manager to store SSH key passphrases, which, in KDE, has always been a pain to get correctly (at least, now, I have a configuration that I know works on all the distributions mentioned above):
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 |
- name: Install kwalletmanager and ksshaskpass become: true ansible.builtin.package: state: present name: - kwalletmanager - ksshaskpass - name: Create autostart directory ansible.builtin.file: path: '~/.config/autostart' mode: 0755 state: directory - name: Copy ssh-add.desktop ansible.builtin.copy: src: "kde-ssh/ssh-add.desktop" dest: "~/.config/autostart/" mode: 0644 # inspired by AUR package plasma-workspace-agent-ssh - name: Create /etc/xdg/plasma-workspace/env/ become: true ansible.builtin.file: path: '/etc/xdg/plasma-workspace/env/' mode: 0755 state: directory - name: Create /etc/xdg/plasma-workspace/shutdown/ become: true ansible.builtin.file: path: '/etc/xdg/plasma-workspace/shutdown/' mode: 0755 state: directory - name: Copy ssh-agent-startup.sh become: true ansible.builtin.copy: src: "kde-ssh/ssh-agent-startup.sh" dest: "/etc/xdg/plasma-workspace/env/" mode: 0755 - name: Copy askpass.sh become: true ansible.builtin.copy: src: "kde-ssh/askpass.sh" dest: "/etc/xdg/plasma-workspace/env/" mode: 0755 - name: Copy ssh-agent-shutdown.sh become: true ansible.builtin.copy: src: "kde-ssh/ssh-agent-shutdown.sh" dest: "/etc/xdg/plasma-workspace/shutdown/" mode: 0755 |
Concerning Molecule, I have several scenarios. As I said, I tested this role in Arch, Ubuntu, and Fedora, so I have a scenario for each operating system. The “default” scenario is Arch, which nowadays is my daily driver.
For Ubuntu, we have a “prepare.yml” file:
1 2 3 4 5 6 7 8 |
--- - name: Prepare hosts: all gather_facts: false tasks: - name: Install python in Ubuntu ansible.builtin.raw: apt update && apt install -y --no-install-recommends python3 sudo changed_when: false |
The reason for this is explained in my previous posts on Ansible and Molecule.
I have a similar “prepare.yml” for the default scenario, Arch.
I have nothing to verify for this role in the “verify.yml”. I just want to ensure that the Ansible role can be run (and is idempotent) in Arch, Ubuntu, and Fedora.
Of course, this is tested on GitHub Actions and can be developed directly on the web IDE Gitpod.
I hope you find this post useful for inspiration on how to use Ansible to automatize your Linux installations 🙂