I am writing netscaler.adc collection for NetScaler devices.
After instantiating AnsibleModule class, we get a module object.
In the module object, there is a params member – module.params
from ansible.module_utils.basic import AnsibleModule
module = AnsibleModule()
print(module.params)
module.params has all the parameters for the resource. For example, if a resource has four attributes – a, b, c, d, and if the user provides only two attributes a and b, I am getting all the four attributes (c and d with their default values.
I do not want to get the non-playbook attributes.
How to achieve this.
My code is below – So far, I was of the assumption that module.params has only the playbook-attributes.
Can someone please help me a way to get only playbook-attributes?
Not that I’ve developed many collection modules myself, but on the ones I did (pretty simple ones actually) I use to get the arguments independently as dict elements instead of getting the whole params dict. For example, if I have these arguments;
Then I can get only the ones I want, e.g. like this:
print(module.params["provider"])
Is that what you were looking for? Also, Notice that you can add the required=False argument to any module_args param instead of assigning a default value.
The solution I found was NOT to use default args as these default args will go with the POST method even if they have not been provided in the playbook.
That’s neat @sumanth-lingappa I’m glad you came up with a solution yourself
Just for housekeeping sake, may I ask you to tick the solved check on the post you believe helped you the most? (of course, you can set your own post as the solution).