Re: [ansible-project] item as part of a variable

2018-04-16 Thread Matt Martz
You will need to construct a key, and reference the value through hostvars
like:

when:
  - hostvars[inventory_hostname][item ~ "_version"] is defined

On Mon, Apr 16, 2018 at 8:46 AM, Michael Renner  wrote:

> Moin,
>
> I'm calling a playbook (ansible 2.4.2.0) with extra-vars for 3 system
> components, e.g. "foo_version=0.11.3 bar_version=0.10.2 baz_version=0.12.1
> env=dev".
>
> There is a statement In the playbook that takes care that this step is
> only executed if the corresponding variable is defined: "{{ item
> }}_version".
>
>   - name: copy war file
> copy:
>   src: "{{ tmpdir.path }}/{{ item }}.war"
>   dest: /opt/tomcat/webapps/
>   owner: tomcat
>   group: root
>   mode: 0440
> when:
>   - "{{ item }}_version" is defined
> with_items:
>   - foo
>   - bar
>   - baz
>
> But this fail:
>
> The offending line appears to be:
>
>   - "{{ item }}_version" is defined
>  ^ here
> We could be wrong, but this one looks like it might be an issue with
> missing quotes.
>
> How can I check if the variable is set?
>
> 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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/9f32f0fa-0748-41e5-a19f-ccbfa0af20cf%40googlegroups.
> com
> 
> .
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-y68Ee-9coSzOh37SC%3D85O2x3mp0cynHohceaaW-tkCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] item as part of a variable

2018-04-16 Thread Brian Coca
That won't work, try:

  - name: copy war file
copy:
  src: "{{ tmpdir.path }}/{{ item }}.war"
  dest: /opt/tomcat/webapps/
  owner: tomcat
  group: root
  mode: 0440
when: item + "_version" in hostvars[inventory_hostname]
with_items:
  - foo
  - bar
  - baz

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7ery-NskYidV9cCpQ7e092rMS08wi8xBodiqqxTupXJog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.