# Package Facts with multiple Packages

**URL:** <https://forum.ansible.com/t/package-facts-with-multiple-packages/37280>\
**Category:** Ansible Project\
**Created:** [October 29, 2022, 1:36pm UTC](https://forum.ansible.com/t/package-facts-with-multiple-packages/37280 "2022-10-29T13:36:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Silvio\_Siefke](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@Silvio\_Siefke](https://forum.ansible.com/u/Silvio_Siefke)\
**Post date:** [October 29, 2022, 1:36pm UTC](https://forum.ansible.com/t/package-facts-with-multiple-packages/37280/1 "2022-10-29T13:36:04Z")

</div>

Hello,

I try to install restic with Ansible and I use multiple Distros.

So I create a vars file with content:

\_restic\_packages:  
default:  
- restic  
- fuse  
- bzip2  
- pigz  
Alpine:  
- restic  
- fuse  
- bzip2  
- pigz  
Archlinux:  
- restic  
- fuse3  
- fuse2fs  
- bzip2  
- pigz  
Debian:  
- restic  
- fuse3  
- fuse2fs  
- bzip2  
- pigz  
FreeBSD:  
- restic  
- fusefs-sshfs  
- fusefs-libs  
- bzip2  
- pigz

restic\_packages: "{{ \_restic\_packages[ansible\_os\_family ~ '-' ~ ansible\_distribution\_major\_version] | default(\_restic\_packages[ansible\_os\_family] | default(\_restic\_packages['default'] )) }}"

The install file in role:

- name: Check installation  
ansible.builtin.package\_facts:  
manager: auto

- name: Install restic  
ansible.builtin.package:  
name: "{{ restic\_packages }}"  
state: present  
when:  
- "'{{ restic\_packages }}' not in ansible\_facts.packages"

This end with:

[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ restic\_packages }} not in ansible\_facts.packages  
fatal: [storage\_fr]: FAILED! =\>  
msg: |-  
The conditional check '{{ restic\_packages }} not in ansible\_facts.packages' failed. The error was: Unexpected templating type error occurred on ({% if ['restic', 'fuse3', 'fuse2fs', 'bzip2', 'pigz'] not in ansible\_facts.packages %} True {% else %} False {% endif %}): unhashable type: 'list'

```
 The error appears to be in &#39;/home/siefke/Public/projects/coding/ansible/roles/core/restic/tasks/install\.yml&#39;: line 3, column 3, but may
 be elsewhere in the file depending on the exact syntax problem\.

 The offending line appears to be:

```

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [October 29, 2022, 2:25pm UTC](https://forum.ansible.com/t/package-facts-with-multiple-packages/37280/2 "2022-10-29T14:25:50Z")

</div>

Hi,

> - name: Install restic  
> ansible.builtin.package:  
> name: "{{ restic\_packages }}"  
> state: present  
> when:  
> - "'{{ restic\_packages }}' not in ansible\_facts.packages"

1. This condition does not do what you want. You are testing whether  
the list of packages is a \*member\* of the set of installed packages.  
(Which does not work, because lists cannot be part of hash sets and  
lists are not hashable.) You want to test for subset, not for  
membership.

2. Why not simply remove the `when:` and let the package action decide  
whether the packages have already been installed or not? The package  
action is supposed to be idempotent.

Cheers,  
Felix
