Hi Dick,
Thanks for your elaborated answer.

The reason for having vars after stat is that I feared the "not defined" 
issue. I never tried to have vars before, but since I will try your 
set_fact approach, this doesn't matter either.

Thanks.


[email protected] schrieb am Mittwoch, 5. Januar 2022 um 20:41:53 UTC+1:

> Hii
>
>
> On Wed, 5 Jan 2022 at 20:09, 'Neil Young' via Ansible Project
> <[email protected]> wrote:
> >
> > And this is all I wanted:
> >
> > # ansible-playbook -l offline -i hosts.cfg test.yml
> >
> > ./test.yml:
> >
> >
> > - hosts: all
> >
> > pre_tasks:
> > # Test if there was a previous source installation of KMS
> > - name: Test if there was a KMS source installation running before
> > stat:
> > path: ~/.kms_installed_from_source
> > register: kms_trace
> >
> > vars:
> > kms_installed_from_source: '{{ true if (kms_trace.stat.exists) else 
> false }}'
>
> You have the 'vars' section after 'pre_tasks', giving the impression
> that this matters, while it doesn't.
> It can be anywhere.
> However, while it can be listed anywhere, it won't always work,
> because kms_installed_from_source won't be available if used in tasks
> that are earlier than the 'stat' task.
>
> Things will be less ambiguous if you use a set_fact task, so it is
> clear where the variable is actually set.
>
> Regarding 'pre_tasks' (as well as post_tasks), I find those somewhat
> confusing. I always have just 'tasks' and then the order of the tasks
> is as they appear in that list. I'm saying because I've seen
> post_tasks being put at the beginning, and the other way around.
>
> The "true if (kms_trace.stat.exists) else false" is unnecessary as
> stat.exists is already a boolean.
> Concluding, if you must use a dedicated variale, then this task (as
> part of just 'tasks') should be sufficient:
>
> - set_fact:
> kms_installed_from_source: '{{ kms_trace.stat.exists }}'
>
> Obviously the stat task needs to be executed before this. But if
> that's listed in that order, there is no ambiguity.
>
> DIck
>

-- 
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/86c6e24b-c404-4124-aa59-a9ca06e1593en%40googlegroups.com.

Reply via email to