This is a total hack, but cute when used:
==
tasks:
- name: foo
set_fact:
items: {{ items.remove('something') and items or items }}
==
This handles the case of remove() returning true or false, depending on
the implementation language returning nothing, true when the list was
modified, and false when it wasn't.
This combines elements of ansible( set_fact ), jinga2( {{ ), and python(
.remove() )
In all honesty, I really don't like these kinds of hacks. I don't like
that the underlying implementation language(python) leaks into the
variable expansion language(jinga2), as it makes reimplementation difficult.
On 10/02/2014 02:17 PM, James Cammarata wrote:
Nothing fishy at all - there is an optimization for certain modules
(primarily apt and yum) where items are combined into a single
execution. This makes these modules way more efficient, since the
underlying package management systems are able to handle a list of
package names at once just as easily.
But yes, the bug appears to be that some later conditional check is
incorrectly being evaluated to make the task be skipped rather than
run. As Matt mentioned above, there is a per-item check with the
conditional to remove individual items, which I *believe* should be
the only conditional check when the items have been merged into a list
like this.
On Thu, Oct 2, 2014 at 1:09 PM, Josh Smift <j...@care.com
<mailto:j...@care.com>> wrote:
JC> Yes, here's a simple reproducer:
JC>
JC> - hosts: localhost
JC> gather_facts: no
JC> vars:
JC> test: ['a', 'b']
JC> tasks:
JC> - shell: echo -e 'a\nb\nc'
JC> register: result
JC> - debug: var=result
JC> - name: do it
JC> yum: name="{{item}}"
JC> with_items: result.stdout_lines
JC> when: item in test
JC>
JC> The output of the "do it" task is:
JC>
JC> TASK: [do it]
JC> *****************************************************************
JC> skipping: [127.0.0.1] => (item=a,b)
This seems fishy to me. Wouldn't you expect an item=a and an
item=b line?
Does item=a,b imply that it's checking to see if the string "a,b"
is in
test (which it isn't)?
Indeed, if you replace 'yum: name="{{item}}"' with 'debug:
var=item, you
get different results:
TASK: [do it]
*****************************************************************
ok: [localhost] => (item=a) => {
"item": "a"
}
ok: [localhost] => (item=b) => {
"item": "b"
}
skipping: [localhost] => (item=c)
Is it surprising that debug treats the items as a list elements,
but yum
treats them as a comma-separated string of elements?
-Josh (j...@care.com
<mailto:j...@care.com>)
This email is intended for the person(s) to whom it is addressed
and may contain information that is PRIVILEGED or CONFIDENTIAL.
Any unauthorized use, distribution, copying, or disclosure by any
person other than the addressee(s) is strictly prohibited. If you
have received this email in error, please notify the sender
immediately by return email and delete the message and any
attachments from your system.
--
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
<mailto:ansible-project%2bunsubscr...@googlegroups.com>.
To post to this group, send email to
ansible-project@googlegroups.com
<mailto:ansible-project@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/21549.38122.295125.36977%40gargle.gargle.HOWL.
For more options, visit https://groups.google.com/d/optout.
--
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
<mailto:ansible-project+unsubscr...@googlegroups.com>.
To post to this group, send email to ansible-project@googlegroups.com
<mailto:ansible-project@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAMFyvFj6DAR0ohof_GBN9Kbx_rjnNw_5ejbxR6Jabdm7MfOLbQ%40mail.gmail.com
<https://groups.google.com/d/msgid/ansible-project/CAMFyvFj6DAR0ohof_GBN9Kbx_rjnNw_5ejbxR6Jabdm7MfOLbQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/542DAF93.7020208%40brainfood.com.
For more options, visit https://groups.google.com/d/optout.