What is search failing against getent_group

I must have a syntax error or don’t understand something, but the following errors out. Am I doing this wrong? or is there something special about trying to search getent_{group,passwd}?

`

  • debug:
    var: getent_group.dba
    when: getent_group.dba is search(“10001”)

RESULT:
FAILED! => {“msg”: “The conditional check ‘getent_group.dba is match("10001")’ failed. The error was: Unexpected templating type error occurred on ({% if getent_group.dba is match("10000") %} True {% else %} False {% endif %}): expected string or buffer\n\nThe error appears to have been in ‘/etc/ansible/playbooks/one-offs/clean_up_users.yml’: line 13, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n”}

CONTENT OF VAR getent_group.dba:
ok: [myserver] => {
“getent_group.dba”: [
“x”,
“10001”,
“”
]
}

`

If I try the following it works, but I don’t understand why the first doesn’t work:
- debug:
var: getent_group.dba
when: getent_group.dba | lower is search("10000")

search operates on a string, and getent_group.dba is a list. Using lower on it is casting the list to a string.

I think you can simplify your conditional:

when: getent_group.dba[1] == “10000”

That will directly evaluate the gid to see if it equals a certain value.

Just use this

   when: "'10001' in getent_group.dba"