-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to use a loop over controller items? #749
Comments
I'm not sure to get you... The code you are showing seems to loop over many organizations... but the I've removed the |
Correct, it's an enhancement requirement. As there were very little activity in enhancement I thought it was better to stick to issue. Sorry about that. I used Organization as an example here. But the requirement is for all kinds of controller. My need is, rather than repeating the block
50 times to apply an identical configuration, I'd much rather have a source list of Org names
and have a way to do something like this:
This of course isn't possible with the actual system. This has been made possible in the controller_roles by adding The simplest way to enable this would probably be to change So that this snippet would work on a set of Org:
then of course the same would be needed for controller_teams, controller_inventories, controller_credentials ... most of the AWX resources. |
I have some things to comment here...
|
thanks for your comment. I'll share my specific use case to give you some perspective. We configure a tower instance from scratch with our infra.controller_configuration based playbook. We do it in an idempotent spirit, meaning we run the same playbook with a CI ever as many time as needed to keep the targets env in sync. (even though we're struggling with deleting object, we mostly do it manually or with An important sub Use case that triggered this request is that we on-board regularly new department of our business, under the form of a dedicated Org. When we onboard a new dept XXXX, we have to perform the following actions:
For now we have to duplicate this basic config for each new org. As we reach ~40 it's becoming hard to maintain. That's the main issue for us, but we have a lot of configs that are identical and that we have to duplicate. Now thinking about it I can see how I could have a subset with only the Orga/Team/Role/Setting and loop over a call to filetree_read+dispatch, with the Org/Team name as a var, from the main playbook. That would work but it doesn't feel proper IMO at the moment. Also it's hard to keep track between controller dependencies as the controller source base grows. All in all, it feels like a good python SDK for Awx/Tower would help a lot :) There use to be one as I remember. |
I'm not sure it will fix your problem, but it is possible to make use of YAML Anchors as part of your definition.
The resultant variable output then is:
This obviously doesn't get it down to a nice singular list but it reduces the vast majority of the repeated code. You'd probably also want to make sure there is sufficient documentation around what's going on here as someone who hasn't come across this notation before may not understand what's going on |
thanks a bunch @Tompage1994, it's a freaking good idea, it totally escaped me to use anchors. This will help me come a long way from where we are now, for the configuration code duplication part. But as you mentioned, I still won't be able to use a list type variable and apply a controller conf to each of its member though. |
It's nice to benefit from the infra.controller abstraction over the ansible.controller collection, but I'm reaching a density in my filetree_read source where a loop notion becomes necessary.
I have enough object to create that I'd need a mecanism like:
rather than to have to duplicate the block 50 times over.
But I don't see how this would be possible in the filetree_read source variables.
Right now it seems that my only option to be able to loop over list of items would be to go back a layer down and start to use ansible.controller.
Some controllers like controller_roles have this use case kind of embedded as it can be applied to both team and teams list, organization and organizations list, etc.
Maybe adding this possibility to all controller object could be a solution, so that a list of names could be used as an entry for any type of object?
The text was updated successfully, but these errors were encountered: