When statements are evaluated for every loop of with_items. So your when
statement will not prevent ansible from attempting to loop over the value.
You will need to ensure that the value is at least an empty list.
Something like:
- name: Install php and packages from php_packages
yum: name={{ item }} enablerepo=epel state=present
with_items: php_packages|default([])
The side effect, is that you also don't need to check that it is defined,
as the default filter will set it to an empty list which has no iterations,
if the var was not defined to begin with.
On Mon, Nov 23, 2015 at 4:28 PM, Alan LaCombe <[email protected]> wrote:
> This test playbook used to work in ansible 1.9.x and is no longer working.
> I have no variables (foo or php_packages)defined for this example.
>
> ---
> - debug: msg "Foo is " {{ foo }}
> when: foo is defined
>
> - debug: msg "Foo is " {{ foo }}
> when: php_packages is defined
>
> - name: Install generic php
> yum: name={{ item }} enablerepo=epel state=present
> with_items:
> - php
> when: php_packages is not defined
>
> - name: Install php and packages from php_packages
> yum: name={{ item }} enablerepo=epel state=present
> with_items: [ '{{ php_packages }}' ]
> when: php_packages is defined
>
>
> I am getting
>
> PLAY [configure and deploy the webservers and application code]
> ****************
>
> TASK [setup]
> *******************************************************************
> ok: [localhost]
>
> TASK [test : debug]
> ************************************************************
> skipping: [localhost]
>
> TASK [test : debug]
> ************************************************************
> skipping: [localhost]
>
> TASK [test : Install generic php]
> **********************************************
> ok: [localhost] => (item=[u'php'])
>
> TASK [test : Install php and packages from php_packages]
> ***********************
> fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR!
> 'php_packages' is undefined"}
>
> PLAY RECAP
> *********************************************************************
> localhost : ok=2 changed=0 unreachable=0 failed=1
>
>
> The debug steps acts correctly so I assume the when clause is working as
> expected.
>
> --
> 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/6aaa9fb5-dfa7-40f9-bbd5-5262e25152ed%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6aaa9fb5-dfa7-40f9-bbd5-5262e25152ed%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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/CAD8N0v-wstctUPTJv3fOdBL48aefn%2B4eM%3D74g%3DA5%3DLpkYD_zHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.