# Two sets of arguments/parameters for one module?

**URL:** <https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365>\
**Category:** Ansible Developer\
**Created:** [July 10, 2020, 4:56am UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365 "2020-07-10T04:56:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rory\_G](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@Rory\_G](https://forum.ansible.com/u/Rory_G)\
**Post date:** [July 10, 2020, 4:56am UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365/1 "2020-07-10T04:56:15Z")

</div>

Hi all,

I’m new to Ansible and a writing a few python network modules. I was wondering if it is possible to write a module that uses one of two different sets of parameters based on a version parameter. For example, I have the two tasks with slightly different parameters that do the same thing. I would like to call the same module for both.

Tasks Pseudocode:

- name: Task Version 1  
test\_task:  
version: 1  
parameter1: test

- name: Task Version 2  
test\_task:  
version: 2  
param\_container:  
parameter1: test

So here the task does the same thing, but the arguments change slightly based on the version. The version must be passed in by the user somehow. Is it possible to write a module that uses different parameters based on another parameter?

I have already tried creating multiple Ansible module objects and creating two separate modules with an abstraction layer, but nothing seems to be working.

Sorry if this is obvious, but I would really appreciate the help!

---

<div class="post-metadata">

**Author:** ![Magnus\_Lubeck](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/magnus_lubeck/32/3905_2.png) [@Magnus\_Lubeck](https://forum.ansible.com/u/Magnus_Lubeck)\
**Post date:** [July 10, 2020, 5:30am UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365/2 "2020-07-10T05:30:47Z")

</div>

I see no problem with doing that.

Just make sure that your module has default values for both parameter1 and param\_container, so that you can enter your method.

Then, once you are in your code, you can check for the version and take proper action.

//magnus

---

<div class="post-metadata">

**Author:** ![Rory\_G](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@Rory\_G](https://forum.ansible.com/u/Rory_G)\
**Post date:** [July 10, 2020, 4:11pm UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365/3 "2020-07-10T16:11:54Z")

</div>

That is helpful, but would it be possible to have two sets of argument\_spec for more complicated differences in the parameters?

example pseudocode for module:

argument\_spec1=dict(…)  
argument\_spec2=dict(…)

# get version from YAML

# pass corresponding argument\_spec to AnsibleModule based on version

It seems like it’s not possible with the standard module, but it would be helpful if there was a way.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [July 10, 2020, 4:25pm UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365/4 "2020-07-10T16:25:43Z")

</div>

Hi,

why not simply have two different modules? (With shared code in module\_utils?)

You could also not use AnsibleModule, but do all the communication by  
yourself (like binary modules). That way you can essentially do what you want.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Rory\_G](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@Rory\_G](https://forum.ansible.com/u/Rory_G)\
**Post date:** [July 13, 2020, 7:21pm UTC](https://forum.ansible.com/t/two-sets-of-arguments-parameters-for-one-module/33365/5 "2020-07-13T19:21:03Z")

</div>

Thank you, that should set me on the right track!
