# Install any flatpaks that we want to use
- block:
- name: Install flatpaks
flatpak:
name: "{{ item.flatpak }}"
state: present
method: user
remote: fedora
become: yes
become_user: dustymabe
with_items:
- { name: eog, flatpak: org.gnome.eog }
- { name: firefox, flatpak: org.mozilla.Firefox }
- { name: gedit, flatpak: org.gnome.gedit }
- { name: gimp, flatpak: org.gimp.GIMP }
- { name: inkscape, flatpak: org.inkscape.Inkscape }
- { name: thunderbird, flatpak: org.mozilla.Thunderbird }
TASK [common : Install flatpaks] ************************************************************************************************************************************************
failed: [media] (item={'name': 'eog', 'flatpak': 'org.gnome.eog'}) => {"ansible_loop_var": "item", "changed": false, "command": "/usr/bin/flatpak install --user -y fedora org.gnome.eog", "item": {"flatpak": "org.gnome.eog", "name": "eog"}, "msg": "Failed to execute flatpak command", "rc": 1, "stderr": "error: Cannot autolaunch D-Bus without X11 $DISPLAY\n", "stderr_lines": ["error: Cannot autolaunch D-Bus without X11 $DISPLAY"], "stdout": "Looking for matches…\nRequired runtime for org.gnome.eog/x86_64/stable (runtime/org.fedoraproject.Platform/x86_64/f32) found in remote fedora\n", "stdout_lines": ["Looking for matches…", "Required runtime for org.gnome.eog/x86_64/stable (runtime/org.fedoraproject.Platform/x86_64/f32) found in remote fedora"]}
https://pagure.io/fedora-lorax-templates/c/cc1155372046baa58f9d2cc27a9e5473bf05a3fb?branch=master has a workaround if you know that you aren't in a D-BUS session. Dealing with the case where DBUS_SESSION_BUS_ADDRESS. might be set or not is a little harder.
@alexlarsson would have an idea whether there's anything that could be reasonably done within Flatpak to make this work automatically. (In general, I don't think every application that has multiple components that talk to each other over D-Bus needs to grow code to launch a private bus. Is Flatpak somehow special?)
I have the same issue - even if I run the flatpak command under my user with su.
su - fansari -c 'flatpak update --assumeyes'
On the other hand: if I run the command
flatpak update --assumeyes
directly under my user - then it works.
Also I noticed that it does not always behave like this. In the past I could even run the flatpak update command directly as rooot.
Background information: I have a script running some tasks like flatpak update and rpm-ostree upgrade. All of these commands - except for the flatpak update - need to be run as root. Sol I tried to put the flatpak update also in this script.
I will try to use this for my next update:
flatpak update --user --assumeyes
I have observed the same, indeed it seems that Ansible flatpak module is broken by this on Fedora 33. I explicitly provided DISPLAY
variable to the module, which then resulted in the following: error: Failed to execute child process “dbus-launch” (No such file or directory)
. So i also explicitly provided also DBUS_SESSION_BUS_ADDRESS
and i made sure the address is valid by logging into the desktop environment with the user i ran Ansible as.
This is what i put onto the Ansible task:
environment:
DISPLAY: :0
DBUS_SESSION_BUS_ADDRESS: unix:path=/run/user/1000/bus
It's not ideal to have to hardcode these variables, but since i only manage my user's flatpaks, it's good enough.
Note that using the become machinectl plugin seems to work for this because it creates a full user session.
become: yes
become_user: dustymabe
become_method: machinectl
The only problem is that I was hitting is that the operation was timing out sometimes so I tried to adjust the timeout and hit an issue with the plugin not properly passing environment variables. I opened an issue for that at ansible-collections/community.general#3809