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

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

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-’)

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 .

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

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.*)

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

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
        Racke