I just wanted to add a note that
lookup('env', 'ENV_VAR') | default('foo')
returns an empty string if ENV_VAR is not defined in the environment, but
if you use
lookup('env', 'ENV_VAR') | default('foo', True)
then if ENV_VAR is not defined (in which case the env lookup plugin returns
an empty string), the second parameter to the default filter tells it to
treat any falsy value as undefined.
On Monday, July 21, 2014 at 12:59:15 PM UTC-5, Tom Hall wrote:
>
> I thought
>
> - name: Clone repo
> git: repo="{{ git_repo }}"
> dest="{{ git_dest }}"
> version="{{ git_version | lookup('env','git_version') |
> default('master') }}"
> notify: reload apache
>
> would work to use the git_version group_var, ENV if it was set and master
> otherwise.
>
> I think I was thinking of | as or rather than a filter when I first wrote
> it but still can't figure out how to do what I want, weirdly the error is
> stderr: fatal: '{{git_repo}}' does not appear to be a git repository
> so I think the whole Jinja templating fails.
>
> If I do
> lookup('env','git_version') | default('master')
> It gets '' if the env var is not set, rather then taking the default as I
> hoped
>
> Thanks,
> Tom
>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/c7533bdf-8b5c-4416-bd3d-7f1091d14299%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.