" when: item in lookup('flattened', [produsers, stgusers])"
I've never seen that syntax used and am slightly surprised it works.
However, what's happening is "item" is the only thing that decides what you
are looping over.
The "when" decides, at that loop iteration, what gets executed.
I would *not* expect to see a lookup inside a "when" conditional. It's not
disallowed, but it's weird enough to be the first time I've seen someone
try it.
Ultimately, it may be possible to string ansible together to do some
weird/clever things because there's a template engine in there, though we
generally stick to idiomatic things in the docs.
I would have suspected:
- debug: msg={{ item }}
with_flatted:
- listone
- listtwo
As the best way to list or iterate over the users in multiple lists at the
same time.
It may be that I'm misinterpreting the question, and you are looking for
another form of iteration, but that seems to be what you want, to me.
On Wed, Sep 24, 2014 at 3:09 PM, Josh Smift <[email protected]> wrote:
> We have a playbook like this:
>
> - hosts: localhost
> gather_facts: false
> vars:
> produsers: [chris, dana]
> stgusers: [pat, sandy]
> allusers: [alex, andy, chris, dan, dana, jamie, pat, sandy, terry]
>
> tasks:
>
> - name: show authorized
> debug: msg={{ item }}
> when: item in lookup('flattened', [produsers, stgusers])
> with_items: allusers
>
> A list of users who should have access to prod, a list of users who should
> have access to stg, and a list of all the users, including some who
> shouldn't have access to either of those things. The task is then intended
> to show the users who are in one list or the other. Thing is, it does this:
>
> TASK: [show authorized]
> *******************************************************
> skipping: [localhost] => (item=alex)
> ok: [localhost] => (item=andy) => {
> "item": "andy",
> "msg": "andy"
> }
> ok: [localhost] => (item=chris) => {
> "item": "chris",
> "msg": "chris"
> }
> ok: [localhost] => (item=dan) => {
> "item": "dan",
> "msg": "dan"
> }
> ok: [localhost] => (item=dana) => {
> "item": "dana",
> "msg": "dana"
> }
> skipping: [localhost] => (item=jamie)
> ok: [localhost] => (item=pat) => {
> "item": "pat",
> "msg": "pat"
> }
> ok: [localhost] => (item=sandy) => {
> "item": "sandy",
> "msg": "sandy"
> }
> skipping: [localhost] => (item=terry)
>
> What are andy and dan doing there? They're not on the right lists! But,
> their names *are* substrings of the names of some of the users who *are*
> on the right lists. Hmm.
>
> We tried this to debug:
>
> - name: show flattened
> debug: msg={{ item }}
> with_items: lookup('flattened', [produsers, stgusers])
>
> That says:
>
> TASK: [show flattened]
> ********************************************************
> ok: [localhost] => (item=chris,dana,pat,sandy) => {
> "item": "chris,dana,pat,sandy",
> "msg": "chris,dana,pat,sandy"
> }
>
> So, a list of users, right? Not so, because here's a similar one, but with
> a literal list of users, not run lookup('flattened', list-of-lists):
>
> - name: show literal
> debug: msg={{ item }}
> with_items: ['chris', 'dana', 'pat', 'sandy']
>
> And that says
>
> TASK: [show literal]
> **********************************************************
> ok: [localhost] => (item=chris) => {
> "item": "chris",
> "msg": "chris"
> }
> ok: [localhost] => (item=dana) => {
> "item": "dana",
> "msg": "dana"
> }
> ok: [localhost] => (item=pat) => {
> "item": "pat",
> "msg": "pat"
> }
> ok: [localhost] => (item=sandy) => {
> "item": "sandy",
> "msg": "sandy"
> }
>
> So it looks like lookup('flattened', list-of-lists) is returning a
> *string* of comma-separated values, rather than a list of values.
>
> with_flattened seems to return a list of values, but we're not sure how to
> use that in this context, because we already need to with_items over
> allusers.
>
> What's the best way to do this? Is there a lookup plugin that works like
> with_flattened, i.e. returns a list of values rather than a string?
>
> -Josh ([email protected])
>
>
>
> 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 [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/21539.5874.237050.514827%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 [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/CA%2BnsWgy%3DgQCvHxGhwpNq_LCn5Zw1gPn%2BoUjj8mZC1D4jV0G53g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.