How to use wilde card to remove packages (dnf)

24 views
Skip to first unread message

@rabin

unread,
Mar 2, 2018, 5:24:40 AM3/2/18
to Ansible Project
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 ?

Kai Stian Olstad

unread,
Mar 2, 2018, 5:35:45 AM3/2/18
to ansible...@googlegroups.com
On 02.03.2018 11:24, @rabin wrote:
> 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

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

--
Kai Stian Olstad

@rabin

unread,
Mar 2, 2018, 6:36:25 AM3/2/18
to Ansible Project
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"
}

Kai Stian Olstad

unread,
Mar 2, 2018, 11:12:02 AM3/2/18
to ansible...@googlegroups.com
On Friday, 2 March 2018 12.36.25 CET @rabin wrote:
> I all ready tried that, same result bascily.

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

--
Kai Stian Olstad

@rabin

unread,
Mar 3, 2018, 3:50:36 PM3/3/18
to Ansible Project
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.

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


Thanks.

Kai Stian Olstad

unread,
Mar 3, 2018, 4:56:06 PM3/3/18
to ansible...@googlegroups.com
On Saturday, 3 March 2018 21.50.36 CET @rabin wrote:
> I was assuming it was possible, because of the example which allow to
> update all packages.

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

- dnf:
list: installed
register: r

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


--
Kai Stian Olstad

Rabin Yasharzadehe

unread,
Mar 3, 2018, 7:20:34 PM3/3/18
to ansible...@googlegroups.com
Nice trick, didn't know about this filter.
much appreciated :)

thanks.

--
Rabin



--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/QtcUScJScVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2976010.m85HJjCiDr%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages