# can we pass a wildcard in a module's parameter's value ?

**URL:** <https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984>\
**Category:** Ansible Project\
**Created:** [October 7, 2020, 9:15pm UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984 "2020-10-07T21:15:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [October 7, 2020, 9:15pm UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/1 "2020-10-07T21:15:05Z")

</div>

hi, again a very simple use case in appearance but that is driving me nuts to realize with ansible, anyone ever done :  
tasks:

- name: run a module  
any\_module:  
users: {{item}} # I want to loop first here  
state: absent  
name: “prefixed-\*” # basically anything that starts with ‘prefixed’

I tried :

- as above just using the wildcard symbol , doesn’t work  
Things that comes to mind :
- use startswith , but can’t find the syntax that would fit here
- use another loop, but that tales me to the slope of nested\_loops , something I was NEVER able to make it working.

any simple possibility to just use wildcard in a string ?

thanks

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 7, 2020, 9:19pm UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/2 "2020-10-07T21:19:48Z")

</div>

I have no idea what your goal is, and without giving a concrete example with an actual module I cannot say.

You want to loop some list variable, but limit to only values that start with prefixed- from that list?

loop: “{{ something|select(‘match’, ‘prefixed-.\*’)|list }}”

Or you could do:

loop: "{{ something }}’  
when: item.startswith(‘prefixed-’)

---

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [October 7, 2020, 9:50pm UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/3 "2020-10-07T21:50:31Z")

</div>

thanks Matt,  
here is the real example , trying to remove multiple IAM policies from a bunch of users

- name: assign policies to a given user  
iam\_policy:  
iam\_type: user  
iam\_name: “{{ item }}”  
state: absent  
policy\_name: “{{ starts\_with(‘database\_access-(ro|rw)’) }}” ## here I need to wildcard to any policy starting with that string .

# policy\_name: “database\_access-(ro | rw)” # the other possibility is to find a switch like here so it can either do database\_access-ro OR database\_access\_rw , regex maybe ?

loop: “{{ my\_users }}”

As I already have one loop for users , I was trying to find a filter that I could directly pass in the ‘policy\_name’ parameter .

---

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [October 7, 2020, 10:53pm UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/4 "2020-10-07T22:53:24Z")

</div>

I am not quite sure what {{something}} was supposed to be here ?

---

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [October 8, 2020, 5:22am UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/5 "2020-10-08T05:22:06Z")

</div>

been reading most of ansible docbut can’t find anything related to this,  
Can’t we just use regular expression for passing a string as a parameter ?

It looks pretty simple case :

a\_module:  
param1: something\_well\_defined  
param2: regex(something\_not\_so\_well\_defined.\*)

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 8, 2020, 6:37am UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/6 "2020-10-08T06:37:54Z")

</div>

Parameters can be many things: strings, lists, dicts, boolenas etc.  
A generic "wild card" or regex therefore doesn't mean much.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 8, 2020, 6:41am UTC](https://forum.ansible.com/t/can-we-pass-a-wildcard-in-a-modules-parameters-value/33984/7 "2020-10-08T06:41:41Z")

</div>

> Parameters can be many things: strings, lists, dicts, boolenas etc.  
> A generic "wild card" or regex therefore doesn't mean much.

The module needs to support the type, so in general a wildcard would only work if the module explicitly supports it.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
