# Multiple module\_args

**URL:** <https://forum.ansible.com/t/multiple-module-args/19710>\
**Category:** Ansible Developer\
**Created:** [November 9, 2015, 9:55am UTC](https://forum.ansible.com/t/multiple-module-args/19710 "2015-11-09T09:55:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 9, 2015, 9:55am UTC](https://forum.ansible.com/t/multiple-module-args/19710/1 "2015-11-09T09:55:08Z")

</div>

Hi,

I am developing a module (python) which I am calling using ansible.runner and I need to so with multiple module args.

For example:

args1 = str(sys.argv[0])

args2 = str(sys.argv[1])  
args3 = str(sys.argv[2])

From what I can tell module\_arg in all my noobness, will only pass a single string quoted string?  
How would I pass multiple arguments?

Thanks,  
Luke

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 9, 2015, 2:32pm UTC](https://forum.ansible.com/t/multiple-module-args/19710/2 "2015-11-09T14:32:25Z")

</div>

Except for a few very special ansible modules like command, module args should be key= value. From the playbook’s point of view this can be specified as a yaml dict or a single string of key= value paid separated by spaces.

Inside of the controller, ansible takes either of these forms and transforms them into a python dictionary. For new style ansible modules (those written in python and using the helper class in lib/ansible/module\_utils/basic.py ) this dict is turned into a string representation and embedded in the module. Then the module is passed over the wire and executed on the remote machine.

On the remote machine, the code inside module\_utils/basic.py takes care of turning the the args back into a python dict from the string representation so that the rest of the code in the middle can access the parameters via that dict.

The easiest module I know of to look at to get the hang of this is ping: [https://github.com/ansible/ansible-modules-core/blob/devel/system/ping.py](https://github.com/ansible/ansible-modules-core/blob/devel/system/ping.py)

It only takes a single parameter (data)  
But you can add more by making new entries in the argument\_spec as you experiment.

-Toshio

---

<div class="post-metadata">

**Author:** ![Luke\_Hinds](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@Luke\_Hinds](https://forum.ansible.com/u/Luke_Hinds)\
**Post date:** [November 9, 2015, 4:33pm UTC](https://forum.ansible.com/t/multiple-module-args/19710/3 "2015-11-09T16:33:49Z")

</div>

Thanks Toshio!

So I could effectly do something like the following:

module = AnsibleModule(  
argument\_spec = dict(  
arg1=dict(required=True, default=None),  
arg2=dict(required=False, default=None),  
arg3=dict(required=False, default=None),  
),  
supports\_check\_mode = True  
)

Where I have a lack of understanding, is how I would pass those values/args over in ansible.runner:

runner = ansible.runner.Runner(  
module\_name=‘testmodule’,  
module\_args=‘arg1 arg2 arg3’  
  
)

or

runner = ansible.runner.Runner(  
module\_name=‘testmodule’,  
module\_args= [‘arg1’,arg2’,arg3’]  
  
)

---

<div class="post-metadata">

**Author:** ![Luke\_Hinds](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@Luke\_Hinds](https://forum.ansible.com/u/Luke_Hinds)\
**Post date:** [November 10, 2015, 1:13am UTC](https://forum.ansible.com/t/multiple-module-args/19710/4 "2015-11-10T01:13:08Z")

</div>

Quick update. Its working now…

module\_args=‘arg1=hello arg2=world’

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [December 15, 2016, 2:30pm UTC](https://forum.ansible.com/t/multiple-module-args/19710/5 "2016-12-15T14:30:03Z")

</div>

In the key=pair, how can I use variables? For example, like this?

`def create_repo_name(repo_name, desc, baseurl, enabled): mod = ansible.runner.Runner( module_name = 'yum_repository' module_args = 'name=repo_name description=desc baseurl=baseurl enabled=enabled' )`
