# Passing parameters to custom module

**URL:** <https://forum.ansible.com/t/passing-parameters-to-custom-module/21288>\
**Category:** Ansible Project\
**Created:** [April 27, 2016, 6:12am UTC](https://forum.ansible.com/t/passing-parameters-to-custom-module/21288 "2016-04-27T06:12:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mona\_Gopal](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mona\_Gopal](https://forum.ansible.com/u/Mona_Gopal)\
**Post date:** [April 27, 2016, 6:12am UTC](https://forum.ansible.com/t/passing-parameters-to-custom-module/21288/1 "2016-04-27T06:12:55Z")

</div>

Hi,

I have written custom modules in python.  
I am calling the modules from my task file like below:

- name: Collect logstash details  
action: get\_logstash\_details **path** ={{ logstash\_path }}  
register: result
- name: Display the logstash details  
debug: var=result

get\_logstash\_details is my custom module.  
path is the parameter i want to pass to the custom module.

This paramter is accessed in custom module as mentioned below  
path=sys.argv[1]

Queries:

1. Is that the right way to send parameters to custom module?

I am getting the below error:  
fatal: [172.19.10.31]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_args”: {“path”: “/opt/logstash\_standalone/logstash-2.1.1/bin/logstash”}, “module\_name”: “get\_logstash\_details”}, “msg”: “unsupported parameter for module: path”}

Thanks in advance,  
Mona G

---

<div class="post-metadata">

**Author:** ![prakul\_singhal](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@prakul\_singhal](https://forum.ansible.com/u/prakul_singhal)\
**Post date:** [April 27, 2016, 9:19am UTC](https://forum.ansible.com/t/passing-parameters-to-custom-module/21288/2 "2016-04-27T09:19:34Z")

</div>

Hi Mona,

please first import the below line in your module:  
from ansible.module\_utils.basic import \*

After importing it use below step to get value of variable:

module = AnsibleModule(argument\_spec = dict( logstash\_path = dict(required=True, aliases=['logstash\_path ']))  
logstash\_path = module.params.get(‘logstash\_path’)

regards  
Prakul

---

<div class="post-metadata">

**Author:** ![Paul\_Markham](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@Paul\_Markham](https://forum.ansible.com/u/Paul_Markham)\
**Post date:** [April 27, 2016, 10:56pm UTC](https://forum.ansible.com/t/passing-parameters-to-custom-module/21288/3 "2016-04-27T22:56:43Z")

</div>

You can also return the information you need as Ansible facts, which means you can just reference them as normal Ansible variables and you don’t have to use ‘register’.

An example of a simple custom module I wrote is [https://github.com/pmarkham/ansible-ipcalc/blob/master/ipcalc](https://github.com/pmarkham/ansible-ipcalc/blob/master/ipcalc)
