Or, better yet in my opinion, set the default value for "level" in group_vars/<name_of_group>.yml, then for hosts which need a different "level" set that in an appropriately named host_vars file, like host_vars/VM-0213.step.zrz.internal.yml.

This let's you expresses facts about hosts as data rather than as results of expressions in set_fact or other tasks, task which you no longer need to run.
--
Todd

On 7/2/23 1:56 PM, Todd Lewis wrote:
There's a problem with your "when:" conditionals.

First of all, throw out the second, because the strings that are "when:" expressions are already being evaluated in a Jinja2 context, so the mustaches shouldn't be there.

In the first option, on this line:
   when: ansible_fqdn == VM-0213.step.zrz.internal
the "ansible_fqdn" part is okay, but the expression on the right-hand side "==" should be a string. Instead it's the value of the variable "VM" minus the octal number 0213's missing attribute "step"'s missing attribute "zrz"'s missing attribute "internal".

So, yeah, no wonder that doesn't work.

Try this instead:
   when: ansible_fqdn == "VM-0213.step.zrz.internal"
and let us know how you get on.
--
Todd

On 7/2/23 11:12 AM, dulhaver via Ansible Project wrote:
hi,

I want to take different sligthly routes in a playbook based on the particular 
remote. All remotes are in the same hosts group.
I am trying to do this by setting a fact based on the ansible_fqdn value.
Based on that fact ('keycloak' in my example here) I am including different 
tasks files.

these 2 options do not work though:

################################################################
- ansible.builtin.set_fact:
     level: keycloak
   when: ansible_fqdn == VM-0312.step.zrz.internal

- ansible.builtin.set_fact:
     level: keycloak
   when: "{{ ansible_fqdn == VM-0312.step.zrz.internal }}"

################################################################

is there a way to achieve this?



--
Todd

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7b948c12-bf0d-9a58-ad1a-623fde893c6f%40gmail.com.

Reply via email to