Closed evgeni closed 4 years ago
I think the name_map
can still be a separate parameter but I like the idea. We also have very common mappings like locations -> location
and organizations -> organization
. Perhaps it should automatically handle those? I also wonder why we have mappings like name -> name
. That sounds like a noop to me.
How do you see modules which can't do this simple run? Would they override the run method?
@ekohl I know, but a mapping name: name
still serves as a filter. Every other parameter will be removed. Also we had the discussion earlier, and my answer was: "Consistency."
I think, we gain something, if those modules look as similar as possible. (At least something to refactor away from them.)
I started some work on the state and name_map parameters here: #337
With #610 merged, I as the author of the original issue consider this done.
SUMMARY
While reviewing #318 and working on slides for an upcoming talk, I noticed that our modules mostly follow the same structure:
name_map
to map Ansible params to Foreman API paramsForemanAnsibleModule
instance that receives aargument_spec
that duplicates some data fromname_map
entity_dict
from the Ansible paramsmodule.connect()
entity = module.find_resource_by_name(…)
entity_dict
with data if we need to reference other entitieschanged = module.ensure_resource_state(…)
module.exit_json(changed=changed)
My crazy idea was to merge the data of
name_map
andargument_spec
into a singledict
(that can be later processed byForemanAnsibleModule
) and make the module look like this:And
module.run()
would be a wrapper like this:This surely won't work for some more complicated modules we have, but for those that "just" ensure entities, this should work.
ISSUE TYPE