with_items but with single module call

44 views
Skip to first unread message

ora...@gmail.com

unread,
Aug 5, 2015, 1:29:01 AM8/5/15
to Ansible Development
Hi,

I'm pretty new to Python but I'm taking a stab at creating some Oracle modules. 

So I'm trying to create a grants module, and I'd like to be able to use with_items the same way that the yum module does (load all items at once) and the reason is that its more effective to add all grants with one statement instead of looping over them.
But,  I cant get it to work. I've looked at the code for the yum module and I 'think' I've done pretty much the same thing.
I can work around this by passing everything as a string, but I think (from a 'setting up playbook parameters' perspective) that runs the risk of getting unwieldy and hard to read after a while.

So the question is: Are there optimizations done elsewhere in core that are specific to the yum/apt modules that make this optimization possible?

regards
/Micke

Jesse Keating

unread,
Aug 5, 2015, 1:35:03 AM8/5/15
to ora...@gmail.com, Ansible Development


- jlk

--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ora...@gmail.com

unread,
Aug 5, 2015, 2:57:41 AM8/5/15
to Ansible Development, ora...@gmail.com
Ok, thanks!

So this is decided on a module-by-module basis and for any iterator when using those specific modules? Any chance of this getting more generic ('toggable')? Not sure how that would impact everything else though...

/M

Peter Oliver

unread,
Aug 5, 2015, 3:18:43 AM8/5/15
to ora...@gmail.com, Ansible Development

On 5 Aug 2015 6:29 am, <ora...@gmail.com> wrote:
>
> I can work around this by passing everything as a string, but I think (from a 'setting up playbook parameters' perspective) that runs the risk of getting unwieldy and hard to read after a while.

From a playbook, it's possible to write complex data structures using YAML syntax.  See, for example, http://docs.ansible.com/ansible/pkg5_module.html#examples, where a list is passed as a parameter.

--
Peter Oliver

ora...@gmail.com

unread,
Aug 5, 2015, 5:11:41 AM8/5/15
to Ansible Development, ora...@gmail.com, ansibl...@mavit.org.uk
yeah, that would work if the grant items are in their own structure, but (in this case) they will have to be matched to a user and each user could have their own set of grants.

Maybe something like this (I'm not saying this is the only structure you should use, but that's how I'd structure it.):

users:
      - username: user1
        grants:
              - priv1
              - priv2
      - username: user2
        grants:
              - priv3
              - priv4

So unless I'm missing something I would have to loop over 'users' with e.g 'with_subelements'. Ideally, for each username I'd like to get all grants for that username and make 1 execution/call to the db. And that is why it would be nice if the yum/apt/etc optimization was available 'on demand'

If every user had the same grants this would work though.

users:
     - user1
     - user2
     - user3

grants:
     - priv1
     - priv2

and I could just do: oracle_grants: user={{ users }} grants={{ grants }} .... And that would be only 1 execution for everything.

/M

Hagai Kariti

unread,
Aug 5, 2015, 6:34:57 AM8/5/15
to ora...@gmail.com, Ansible Development, ansibl...@mavit.org.uk
The proper solution is, however, to allow modules to request loops be squashed... The current implementation is hacky.

--

ora...@gmail.com

unread,
Aug 5, 2015, 7:10:55 AM8/5/15
to Ansible Development, ora...@gmail.com, ansibl...@mavit.org.uk
> The proper solution is, however, to allow modules to request loops be squashed... The current implementation is hacky.

yes, that would be most welcome.
Reply all
Reply to author
Forward
0 new messages