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