Questions regarding "when: condition"

The commented section of the following code works. I was trying to simplify it by adding with_items; however, it seems to change the way it is evaluated?.. at least that is my guess based on the verbosity:

`
skipping: [ansible-oel6] => (item=ansible) => {
“changed”: false,
“item”: “ansible”,
“skip_reason”: “Conditional result was False”
}

`

Playbook.

`

Using with_items like you are, you would need to use search(item) without the quotes around item. Otherwise “item” is treated as the string item, instead of the variable called item.

That is good to know, but I made the change and still experience the issue; however, with that info I changed it to the following which works for the first section:

`
when: item in ansible_hostname

`

  when: ansible_hostname | lower | search("item")
# when: ansible_hostname | lower | search("prod") or
# ansible_hostname | lower | search("backup") or
# ansible_hostname | lower | search("nfs") or
# ansible_hostname | lower | search("ansible")
  with_items:
    - prod
    - backup
    - nfs
    - ansible
  failed_when: false

So, I have a couple of questions.
1. What would be the proper way to see if the hostname contains "splat"
using with_items?

You got the answer from Matt, and that should work.

An alternative is to not use with_items but just use regex or.

  when: ansible_hostname | lower is search("prod|backup|nfs|ansible")

2. What would be the reverse of this? (ie not in, or not contained, etc)

  when: not (ansible_hostname | lower is search("prod|backup|nfs|ansible"))

Oh, I like that. Thank you.