Up until recently I’ve been using a bone-headed setup.sh shell script to setup my desktop clients based on Rocky Linux 8 and a heavily customized KDE desktop.
I’ve been learning to use Ansible for some time now (with a few false starts) and I’m currently translating this script into Ansible’s way of doing things:
In the original setup.sh script I have a replace_menus() function that loops through *.desktop files in /usr/share/applications and other places and replaces some of these with a custom version, but only if they exist in the first place.
I wonder how I could possibly translate this into Ansible code. Here’s what should happen:
loop through all custom desktop entries in the templates/ directory.
If the corresponding .desktop file exists in /usr/share/applications, then replace it with the custom version from templates/.
If it doesn’t exist, then don’t install the template.
In other words: install the template only if the target already exists.