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
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
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.
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:
grants:
and I could just do: oracle_grants: user={{ users }} grants={{ grants }} … And that would be only 1 execution for everything.
/M
The proper solution is, however, to allow modules to request loops be squashed… The current implementation is hacky.
The proper solution is, however, to allow modules to request loops be squashed… The current implementation is hacky.
yes, that would be most welcome.