Re: [ansible-project] with_items and array concatenation?

2014-06-06 Thread Michael DeHaan
The first problem here is not about sets or unions or anything.

The issue is with_items wants a single list to walk over, not a list of two
lists.

So

with_items:  variable_ame

works

as does

with_items:
   - dog
   - cat
   - fish

With hard coded strings

But if you want to walk two lists, that's with_nested.

Here, though you do want to add them together.

I just wanted to mention why you were seeing groups[A] literally in the
first logfile above.



On Thu, Jun 5, 2014 at 10:26 AM, C. Morgan Hamill cham...@wesleyan.edu
wrote:

 Excerpts from Dmitry Makovey's message of 2014-06-04 18:17:04 -0400:
  Winning combination turned out to be:
 
  ( groups['A']+groups['B'] ) | unique
 
  I do like how simple it looks vs
 
  ( groups['A']|union (groups['B']))| unique

 Just FYI, the 'unique filter in the latter form is redundant; this
 should work fine:

 groups['A']|union(groups['B')

 Sets, by definition, have no duplicate items.
 --
 Morgan

 --
 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/1401978298-sup-8285%40al.wesleyan.edu
 .
 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/CA%2BnsWgwP24dioO_kXnXLYSxCBm49CSwDtTOH%3DYc1i_5UpBdTvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-05 Thread C. Morgan Hamill
Excerpts from Dmitry Makovey's message of 2014-06-04 18:17:04 -0400:
 Winning combination turned out to be:
 
 ( groups['A']+groups['B'] ) | unique
 
 I do like how simple it looks vs 
 
 ( groups['A']|union (groups['B']))| unique

Just FYI, the 'unique filter in the latter form is redundant; this
should work fine:

groups['A']|union(groups['B')

Sets, by definition, have no duplicate items.
--
Morgan

-- 
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/1401978298-sup-8285%40al.wesleyan.edu.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] with_items and array concatenation?

2014-06-04 Thread Dmitry Makovey
Hi, 

I've got a usecase where I'd like to iterate over several servers based on 
groups, so task looks like:

- name: group A  B
  shell: echo {{ item }}  /tmp/log
  with_items:
  - groups[A]
  - groups[B]

so what I get in /tmp/log is:

groups['A']
groups['B']

Now, eliminating either group I can get:

- name: group A
  shell: echo {{ item }}  /tmp/log
  with_items: groups[A]
 
I get proper result. 

I'm pretty certain I've seen this topic come up recently but can't find it 
anymore. Any pointers (including links to other topics) are welcome.

P.S.
for bonus points - can I do set-like concatenation - i.e. eliminate 
duplicates? 

-- 
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/9c508e6f-3d70-4c6d-a357-330e1eabfd18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-04 Thread Adam Heath

On 06/04/2014 04:47 PM, Dmitry Makovey wrote:

  with_items: groups[A]


ansible uses jinga2.  Look up that syntax.  Then, off the top of my 
head, may not be exactly right, but:


groups[A].concat(groups[B]) | set | list

Some of that is python syntax(the contact, check jinga2 and python 
docs), and the |set|list is jinga2.


--
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/538F94A6.1030402%40brainfood.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-04 Thread Dmitry Makovey
nice try - but no dice:

fatal: [192.168.0.138] = with_items expects a list or a set

FATAL: all hosts have already failed -- aborting

I even played a bit and checked python syntax making it:

groups['A'].extend(groups['B'])|set

with or without last list filter with original syntax or with my 
correction it fails as per above. - doesn't help much to pinpoint 
where the problem is.

-- 
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/dbf95bca-a694-42ec-b5f8-5a607b202157%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-04 Thread Dmitry Makovey
thanks to your hint I'm one step closer:

- name: group A  B
  shell: echo {{ item }}  /tmp/log
  with_items: groups[A] + groups[B]

however I still can't figure out how to make a set out of the result.

-- 
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/e66dc70b-6c54-4324-a798-f7d5d7018478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-04 Thread Matt Martz
You might want to take a look at the 'set' filters provided by ansible at
http://docs.ansible.com/playbooks_variables.html#set-theory-filters

I imagine something like:

with_items: groups['A']|union(groups['B'])|unique

would work.

I doubt it is needed, but you might have to add |list onto the end of that.

I think jinja2 addition may also work:

with_items: (groups['A'] + groups['B'])|unique


On Wed, Jun 4, 2014 at 4:57 PM, Dmitry Makovey droopy4...@gmail.com wrote:

 nice try - but no dice:

 fatal: [192.168.0.138] = with_items expects a list or a set

 FATAL: all hosts have already failed -- aborting

 I even played a bit and checked python syntax making it:

 groups['A'].extend(groups['B'])|set

 with or without last list filter with original syntax or with my
 correction it fails as per above. - doesn't help much to pinpoint
 where the problem is.

 --
 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/dbf95bca-a694-42ec-b5f8-5a607b202157%40googlegroups.com
 https://groups.google.com/d/msgid/ansible-project/dbf95bca-a694-42ec-b5f8-5a607b202157%40googlegroups.com?utm_medium=emailutm_source=footer
 .

 For more options, visit https://groups.google.com/d/optout.




-- 
Matt Martz
m...@sivel.net
http://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/CAD8N0v8kpHxPd5q-UiiN%2B7G-CDG7WSCv-Cxv_fwio%2BazPmJ%2Baw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] with_items and array concatenation?

2014-06-04 Thread Dmitry Makovey
Thanks Matt and Adam!

Winning combination turned out to be:

( groups['A']+groups['B'] ) | unique

I do like how simple it looks vs 

( groups['A']|union (groups['B']))| unique

since in my case I have more groups to add and it is very simple with + 
and less error-prone.

-- 
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/fc93fa6b-72eb-4cab-a4b7-3a7b6153f659%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.