On Sun, May 16, 2021 at 2:26 PM Vladimir Botka wrote:
> > > I cannot use a default because this whole thing is relying
> > > on whether it's defined or not later to take different actions.
> > > the fuller example is:
> > >
> > > - name: determine_subnet
> > > when: >
> > > project == project_bake
> > > or hostvars[target].ipnet is defined
> > > set_fact:
> > > subnet: '{{
> > > (project == project_bake) | ternary(
> > > subnet_bake, determined_subnet
> > > )}}'
> >
> > What value of *subnet* do you want to set when '(project !=
> > project_bake) and (determined_subnet is undefined)' ?
>
> When the corresponding alternatives shall always be defined the
> defaults can't hurt, e.g.
>
> - set_fact:
> subnet: '{{ (project == project_bake)|
> ternary(subnet_bake|default(None),
> determined_subnet|default(None) }}'
Unfortunately that doesn't work, I tried it before. Because it's
so indirect, it needs a default at the level that gets referenced,
not the outer level of the indirection. It gets:
localhost failed | msg: The task includes an option with an
undefined variable. The error was: {{subnets[ip_cidrnet]}}:
{{ip_network}}/{{ip_prefix}}: {{ip_host | ipaddr('network')}}:
{{hostvars[ip_referent].ipnet}}:
'ansible.vars.hostvars.HostVarsVars object' has no attribute
'ipnet'
If only it would not try to dereference the thing, because it's
never actually consulted for a value, as it's the OR with a
true condition. That's the part I still don't get, why it's
happening at all.
Anyways, I have worked around it at this point by splitting
into two separate conditions with "when". I just wanted
to understand why. I still don't understand why, but that
happens sometimes... thanks.
--
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/CACRKOwx8453FL09x1C9cFf%2BW_VNq%3DMPupanktos_WbC58p8sSw%40mail.gmail.com.