Repository: ansible-collections/community.general

Issue:
community.general.flatpak module isn't idempotent when installing packages
### Summary

I'm trying to install a list of flatpaks

`roles/05_packages/tasks/flatpak.yml`

```
---
- name: Add Flathub repository
  community.general.flatpak_remote:
    name: flathub
    state: present
    flatpakrepo_url: https://flathub.org/repo/flathub.flatpakrepo
  become: true

- name: Install flatpaks
  community.general.flatpak:
    name: "{{ flatpaks }}"
    state: present
    remote: flathub
```

`group_vars/all.yml`

```
flatpaks:
  - com.discordapp.Discord
  - com.github.tchx84.Flatseal
  - com.slack.Slack
  - com.spotify.Client
  - com.valvesoftware.Steam
  - com.valvesoftware.Steam.CompatibilityTool.Proton
  - org.gtk.Gtk3theme.Adwaita-dark
  - org.gtk.Gtk3theme.Yaru-dark
  - org.gtk.Gtk3theme.Yaru-light
  - us.zoom.Zoom
```

I get the following error on `Install flatpaks` (with `-vvvv`) and the step isn't idempotent:

```
TASK [05_packages : Install flatpaks] **********************************************************************************************************************
task path: /home/logan/Downloads/development/ansible-arch-linux/roles/05_packages/tasks/flatpak.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: logan
<127.0.0.1> EXEC /bin/sh -c 'echo ~logan && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/logan/.ansible/tmp `"&& mkdir "` echo /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316 `" && echo ansible-tmp-1680122097.6710317-47671-245080701797316="` echo /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316 `" ) && sleep 0'
Using module file /home/logan/.ansible/collections/ansible_collections/community/general/plugins/modules/flatpak.py
<127.0.0.1> PUT /home/logan/.ansible/tmp/ansible-local-470561tlmi1eo/tmpjxbhn9a3 TO /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/ /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.10 /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/ > /dev/null 2>&1 && sleep 0'
changed: [127.0.0.1] => {
    "changed": true,
    "command": "/usr/bin/flatpak install --system --noninteractive flathub com.valvesoftware.Steam.CompatibilityTool.Proton org.gtk.Gtk3theme.Adwaita-dark org.gtk.Gtk3theme.Yaru-dark org.gtk.Gtk3theme.Yaru-light",
    "invocation": {
        "module_args": {
            "executable": "flatpak",
            "method": "system",
            "name": [
                "com.discordapp.Discord",
                "com.github.tchx84.Flatseal",
                "com.slack.Slack",
                "com.spotify.Client",
                "com.valvesoftware.Steam",
                "com.valvesoftware.Steam.CompatibilityTool.Proton",
                "org.gtk.Gtk3theme.Adwaita-dark",
                "org.gtk.Gtk3theme.Yaru-dark",
                "org.gtk.Gtk3theme.Yaru-light",
                "us.zoom.Zoom"
            ],
            "no_dependencies": false,
            "remote": "flathub",
            "state": "present"
        }
    },
    "rc": 0,
    "stderr": "Skipping: com.valvesoftware.Steam.CompatibilityTool.Proton/x86_64/stable is already installed\nSkipping: org.gtk.Gtk3theme.Adwaita-dark/x86_64/3.22 is already installed\nSkipping: org.gtk.Gtk3theme.Yaru-dark/x86_64/3.22 is already installed\nSkipping: org.gtk.Gtk3theme.Yaru-light/x86_64/3.22 is already installed\n",
    "stderr_lines": [
        "Skipping: com.valvesoftware.Steam.CompatibilityTool.Proton/x86_64/stable is already installed",
        "Skipping: org.gtk.Gtk3theme.Adwaita-dark/x86_64/3.22 is already installed",
        "Skipping: org.gtk.Gtk3theme.Yaru-dark/x86_64/3.22 is already installed",
        "Skipping: org.gtk.Gtk3theme.Yaru-light/x86_64/3.22 is already installed"
    ],
    "stdout": "",
    "stdout_lines": []
}

```

### Issue Type

Bug Report

### Component Name

community.general.flatpak

### Ansible Version

```console (paste below)
ansible [core 2.14.4]
  config file = /home/logan/Downloads/development/ansible-arch-linux/ansible.cfg
  configured module search path = ['/home/logan/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/logan/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201] (/usr/bin/python)
  jinja version = 3.1.2
  libyaml = True
```


### Community.general Version

```console (paste below)
# /home/logan/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 6.5.0
```


### Configuration

```console (paste below)
ANSIBLE_FORCE_COLOR(/home/logan/Downloads/development/ansible-arch-linux/ansible.cfg) = True
CONFIG_FILE() = /home/logan/Downloads/development/ansible-arch-linux/ansible.cfg
DEFAULT_HOST_LIST(/home/logan/Downloads/development/ansible-arch-linux/ansible.cfg) = ['/home/logan/Downloads/development/ansible-arch-linux/hosts']
DIFF_ALWAYS(/home/logan/Downloads/development/ansible-arch-linux/ansible.cfg) = True

```


### OS / Environment

Arch Linux

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
`roles/05_packages/tasks/flatpak.yml`

```
---
- name: Add Flathub repository
  community.general.flatpak_remote:
    name: flathub
    state: present
    flatpakrepo_url: https://flathub.org/repo/flathub.flatpakrepo
  become: true

- name: Install flatpaks
  community.general.flatpak:
    name: "{{ flatpaks }}"
    state: present
    remote: flathub
```

`group_vars/all.yml`

```
flatpaks:
  - com.discordapp.Discord
  - com.github.tchx84.Flatseal
  - com.slack.Slack
  - com.spotify.Client
  - com.valvesoftware.Steam
  - com.valvesoftware.Steam.CompatibilityTool.Proton
  - org.gtk.Gtk3theme.Adwaita-dark
  - org.gtk.Gtk3theme.Yaru-dark
  - org.gtk.Gtk3theme.Yaru-light
  - us.zoom.Zoom
```


### Expected Results

I expected the step to be idempotent (the packages are already installed).

### Actual Results


I get the following error on `Install flatpaks` (with `-vvvv`) and the step isn't idempotent:

```
TASK [05_packages : Install flatpaks] **********************************************************************************************************************
task path: /home/logan/Downloads/development/ansible-arch-linux/roles/05_packages/tasks/flatpak.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: logan
<127.0.0.1> EXEC /bin/sh -c 'echo ~logan && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/logan/.ansible/tmp `"&& mkdir "` echo /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316 `" && echo ansible-tmp-1680122097.6710317-47671-245080701797316="` echo /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316 `" ) && sleep 0'
Using module file /home/logan/.ansible/collections/ansible_collections/community/general/plugins/modules/flatpak.py
<127.0.0.1> PUT /home/logan/.ansible/tmp/ansible-local-470561tlmi1eo/tmpjxbhn9a3 TO /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/ /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3.10 /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/AnsiballZ_flatpak.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/logan/.ansible/tmp/ansible-tmp-1680122097.6710317-47671-245080701797316/ > /dev/null 2>&1 && sleep 0'
changed: [127.0.0.1] => {
    "changed": true,
    "command": "/usr/bin/flatpak install --system --noninteractive flathub com.valvesoftware.Steam.CompatibilityTool.Proton org.gtk.Gtk3theme.Adwaita-dark org.gtk.Gtk3theme.Yaru-dark org.gtk.Gtk3theme.Yaru-light",
    "invocation": {
        "module_args": {
            "executable": "flatpak",
            "method": "system",
            "name": [
                "com.discordapp.Discord",
                "com.github.tchx84.Flatseal",
                "com.slack.Slack",
                "com.spotify.Client",
                "com.valvesoftware.Steam",
                "com.valvesoftware.Steam.CompatibilityTool.Proton",
                "org.gtk.Gtk3theme.Adwaita-dark",
                "org.gtk.Gtk3theme.Yaru-dark",
                "org.gtk.Gtk3theme.Yaru-light",
                "us.zoom.Zoom"
            ],
            "no_dependencies": false,
            "remote": "flathub",
            "state": "present"
        }
    },
    "rc": 0,
    "stderr": "Skipping: com.valvesoftware.Steam.CompatibilityTool.Proton/x86_64/stable is already installed\nSkipping: org.gtk.Gtk3theme.Adwaita-dark/x86_64/3.22 is already installed\nSkipping: org.gtk.Gtk3theme.Yaru-dark/x86_64/3.22 is already installed\nSkipping: org.gtk.Gtk3theme.Yaru-light/x86_64/3.22 is already installed\n",
    "stderr_lines": [
        "Skipping: com.valvesoftware.Steam.CompatibilityTool.Proton/x86_64/stable is already installed",
        "Skipping: org.gtk.Gtk3theme.Adwaita-dark/x86_64/3.22 is already installed",
        "Skipping: org.gtk.Gtk3theme.Yaru-dark/x86_64/3.22 is already installed",
        "Skipping: org.gtk.Gtk3theme.Yaru-light/x86_64/3.22 is already installed"
    ],
    "stdout": "",
    "stdout_lines": []
}

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/flatpak.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/flatpak.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @JayKayy @oolongbrothers
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I think the error is in [plugins/modules/flatpak.py](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/flatpak.py) line 218 the "--app" option.
"org.gtk.Gtk3theme.*" is NO app. 

Resolving patch:
diff --git a/plugins/modules/flatpak.py b/plugins/modules/flatpak.py
--- a/plugins/modules/flatpak.py
+++ b/plugins/modules/flatpak.py
@@ -215,7 +215,7 @@ def uninstall_flat(module, binary, names, method):
 
 def flatpak_exists(module, binary, names, method):
     """Check if the flatpaks are installed."""
-    command = [binary, "list", "--{0}".format(method), "--app"]
+    command = [binary, "list", "--{0}".format(method)]
     output = _flatpak_command(module, False, command)
     installed = []
     not_installed = []


Test patch: