I asked the question already on stackoverflow, but figured, that this could be a better place to get an answer: I want to provision a virtual machine with Ubuntu 16 LTS using vagrant and ansible (local). Part of the provisioning is to add and remove some Unity launcher icons for a user that is also created by the same script. The script is started from the vagrant user. After searching through several related questions, I tried variations of

  • dbus-launch --exit-with-session before the gsettings command
  • become_flags: '-i'
  • become_flags: '-H'
  • become_flags: '-E'

on the following basic ansible command

- name: Remove Launcher Icons
  command: gsettings set com.canonical.Unity.Launcher favorites "['application://org.gnome.Nautilus.desktop', 'application://firefox.desktop', 'application://gnome-terminal.desktop', 'application://atom.desktop', 'application://unity-control-center.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices']"
  become: true
  become_user: "{{ user }}"

So far, no success, BUT running the command as a logged in user works.

EDIT My best appoach for a solution would be launching a shell script from ansible instead of doing the change in ansible directly. However, I am not sure how it should look like.

  • 1
    If your other question is still on Stackoverflow, please delete that one. Cross-posted questions are frowned upon on SE network – Sergiy Kolodyazhnyy Nov 9 '16 at 17:06
  • OK, thank you for the hint, I will delete the other one. – grackkle Nov 9 '16 at 22:55

I recommend you place a .desktop file into each user's ~/.config/autostart folder that will call launcher setup script. Alternatively, place .desktop file into /etc/xdg/autostart so that script runs for every user, but then you'll need to grab username and find user launcher config in some form of database. Id personally use Python script that reads json file with username: launcher list valies, because it's simple.

| improve this answer | |
  • So, if I understand you correctly, the script then runs, whenever a user logs in, as that user. This would also mean, that the script must handle later additions to the launcher by the user (at least not overwrite them). – grackkle Nov 10 '16 at 12:52
  • @bln-tom technically, yes. If your user adds something to launcher, normally that'd stay there. But you have a script that alters the launcher each time, so the has to be something to detect changes as well. – Sergiy Kolodyazhnyy Nov 10 '16 at 13:00
  • I plan to let the shell file also create a extra file as a marker that it has been executed. So on the second provisioning run, I let the shell file remove the .desktop file again – grackkle Nov 13 '16 at 14:54
  • @bin-tom I rolled back the additions you made to my answer. I appreciate the improvement but the code you wrote isn't my original work, hence feel like it's wrong for me to take credit for it. If you wish, please post your own answer with that content. I understand and don't mind if unaccepting my post is necessary – Sergiy Kolodyazhnyy Nov 15 '16 at 0:05

I've also struggled with setting the launcher favorites via ansible.

For me the solution was to use the ansible dconf module instead of gsettings:

- name: set icons/applications
    key: /com/canonical/unity/launcher/favorites
    value: "{{ launcher_favorites }}"
    state: present

I guess it also works with other users via become_user (but I haven't tested it).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.