Closed gevalo1 closed 5 years ago
Running ansible from git clone, noticed the above warning. So I ran a git pull to make sure I'm running the latest version. Now running commit 2128e7c14f from stable-2.8 branch.
I have this code at the end of a block in a role I have this:
when:
- plex_repo
Defined in defaults as
plex_repo: yes
Also tried:
plex_repo: true
and
plex_repo: True
Block above this one has:
when:
- not plex_repo
And does not give deprecated warning. These are the only two places I reference plex_repo.
Is this really intended behavior?
Here's the documentation that seems to say this is fine: https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html
This goes away when I change:
when: foo
to:
when: foo == true
but like @coledarr, I'm confused whether we're really supposed to write it like this from now on.
I found this in the porting guide:
Ah - just discovered you can do also:
when: foo|bool
This was fixed in #64 / https://github.com/geerlingguy/ansible-role-ntp/commit/99955a37a7856becf0a6eef249dba1bf60e3a09d
It seems that it's supposed to use
when: foo|bool
But in this case if foo is undefined, it throws error. so I need to do something like
when: foo is defined and (foo | bool)
Is there any more elegant solution to get true result if foo == True, and false in all other cases?
@PKPublicCode - In the case of the NTP role, the variable should always be defined... right? Or are you asking in general / relating to something other than the NTP role?
My last question was "in general"... Probably I used wrong thread for it.
@PKPublicCode - No problem, glad to see you here! There's not really a better way to do it currently (I know there's some shortcut in PHP like is_empty($var)
, but nothing like that afaict in Python or Jinja. I'd ask more though on Stack Exchange or Ansible's IRC channels.
This can also happen when the variable has '' or "", it guess the auto bool typecasting will be disabled in ansible 2.12.
Statement like when: foobar
Need to have a variable like foobar: true
and not foobar: 'true'
An alternative for when: foo is defined and (foo | bool)
is when: foo | default(false) | bool
This warning is thrown by the
Ensure NTP is running and enabled as configured.
&Generate ntp.conf file
tasks in ansible 2.8 (currently unreleased dev).