# Use Ansible to replace \*.desktop files by custom versions ?

**URL:** <https://forum.ansible.com/t/use-ansible-to-replace-desktop-files-by-custom-versions/38699>\
**Category:** Ansible Project\
**Created:** [February 26, 2024, 5:29pm UTC](https://forum.ansible.com/t/use-ansible-to-replace-desktop-files-by-custom-versions/38699 "2024-02-26T17:29:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlinux](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/microlinux/32/2968_2.png) [@microlinux](https://forum.ansible.com/u/microlinux)\
**Post date:** [February 26, 2024, 5:29pm UTC](https://forum.ansible.com/t/use-ansible-to-replace-desktop-files-by-custom-versions/38699/1 "2024-02-26T17:29:32Z")

</div>

Hi,

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:

\* [https://gitlab.com/kikinovak/rocky-8-desktop](https://gitlab.com/kikinovak/rocky-8-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:

\* [https://gitlab.com/kikinovak/rocky-8-ansible](https://gitlab.com/kikinovak/rocky-8-ansible)

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:

1. Loop through all custom desktop entries in the templates/ directory.

2. If the corresponding .desktop file exists in /usr/share/applications, then replace it with the custom version from templates/.

3. If it doesn’t exist, then don’t install the template.

4. In other words: install the template only if the target already exists.

Any idea how I could possibly translate this into Ansible code ?

Cheers from the sunny South of France,

Niki
