# How to use wilde card to remove packages (dnf)

**URL:** <https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886>\
**Category:** Ansible Project\
**Created:** [March 2, 2018, 10:24am UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886 "2018-03-02T10:24:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_rabin](https://avatars.discourse-cdn.com/v4/letter/_/da6949/32.png) [@\_rabin](https://forum.ansible.com/u/_rabin)\
**Post date:** [March 2, 2018, 10:24am UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/1 "2018-03-02T10:24:39Z")

</div>

Hello all,

I like to use Ansible to remove few packages, but it seem not to support the wildecard option for package name matching.

- name: Remove Packages  
package:  
name: “{{ item }}”  
state: absent  
tags:
- packages\_remove  
with\_items:
- b43-\*
- hexchat
- libreoffice\*

In the above example I was expecting the for “b43-\*” to match b43-openfwwf and b43-fwcutter but non of them was removed.  
same for libreoffice, here is the output with -vvv

`ok: [localhost] => (item=libreoffice*) => { "changed": false, "invocation": { "module_args": { "autoremove": null, "conf_file": null, "disable_gpg_check": false, "disablerepo": [], "enablerepo": [], "installroot": "/", "list": null, "name": ["libreoffice*"], "state": "absent" } }, "item": "libreoffice*", "msg": "Nothing to do" }`

Any hints ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 2, 2018, 10:35am UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/2 "2018-03-02T10:35:25Z")

</div>

Package is a very generic module with no extra functionality.  
For more functionality you need to use the module for your package system.

---

<div class="post-metadata">

**Author:** ![\_rabin](https://avatars.discourse-cdn.com/v4/letter/_/da6949/32.png) [@\_rabin](https://forum.ansible.com/u/_rabin)\
**Post date:** [March 2, 2018, 11:36am UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/3 "2018-03-02T11:36:25Z")

</div>

I all ready tried that, same result bascily.

`  
ok: [localhost] =\> (item=[u’b43-openfwwf’, u’b43-fwcutter’, u’hexchat’, u’libreoffice\*‘, u’claws-mail’]) =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“autoremove”: true,  
“conf\_file”: null,  
“disable\_gpg\_check”: false,  
“disablerepo”: ,  
“enablerepo”: ,  
“installroot”: “/”,  
“list”: null,  
“name”: [  
“b43-openfwwf”,  
“b43-fwcutter”,  
“hexchat”,  
“libreoffice\*”,  
“claws-mail”  
],  
“state”: “absent”  
}  
},  
“item”: [  
“b43-openfwwf”,  
“b43-fwcutter”,  
“hexchat”,  
“libreoffice\*”,  
“claws-mail”  
],  
“msg”: “Nothing to do”  
}

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 2, 2018, 4:11pm UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/4 "2018-03-02T16:11:33Z")

</div>

When I check the documentation for the dnf module it has nothing about wildcard so it doesn't support that.

---

<div class="post-metadata">

**Author:** ![\_rabin](https://avatars.discourse-cdn.com/v4/letter/_/da6949/32.png) [@\_rabin](https://forum.ansible.com/u/_rabin)\
**Post date:** [March 3, 2018, 8:50pm UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/5 "2018-03-03T20:50:36Z")

</div>

I was assuming it was possible, because of the example which allow to update all packages.

`

- name: upgrade all packages  
dnf:  
name: “\*”  
state: latest  
`

but it seems it is handled specifically in the code, and not passed directly to the dnf command.

```auto
if names == ['*'] and state == 'latest':
    base.upgrade_all()

```

Thanks.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 3, 2018, 9:55pm UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/6 "2018-03-03T21:55:44Z")

</div>

You probably have a workaround, but just in case you don't this should work to remove all packages staring with libreoffice

&nbsp;&nbsp;- dnf:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list: installed  
&nbsp;&nbsp;&nbsp;&nbsp;register: r

&nbsp;&nbsp;- dnf:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: "{{ r.results | selectattr('name', 'search', '^libreoffice') | map(attribute='name') | list }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state: absent

---

<div class="post-metadata">

**Author:** ![\_rabin](https://avatars.discourse-cdn.com/v4/letter/_/da6949/32.png) [@\_rabin](https://forum.ansible.com/u/_rabin)\
**Post date:** [March 4, 2018, 12:19am UTC](https://forum.ansible.com/t/how-to-use-wilde-card-to-remove-packages-dnf/26886/7 "2018-03-04T00:19:56Z")

</div>

Nice trick, didn’t know about this filter.

much appreciated 🙂

thanks.
