'Custom Ansible module throws unsupported arguments when passing list as parameter
I am writing custom module but when I put the type as list and pass the values like below, I get the error
unsupported parameters
For type string it is working fine.
What is the correct way to pass the list arguments if, in the custom module, we have declared the type as list?
Usage:
- test_module:
url : 'htpp://xxxxx'
computers:
- a
- b
Modulexxxx.py
module_args = dict(
url==dict(type='str', required=True),
computers=dict(type='list', required=False)
)
Solution 1:[1]
From what I can see, the error
Unsupported parameters for (test_module) module: computers
Means that you did not properly feed your expected parameters in the argument_spec
of the instantiation of the object AnsibleModule
.
Here is a MVP to have your arguments taken into account:
test_module.py
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec=dict(
url=dict(type='str', required=True),
computers=dict(type='list', required=False),
)
)
params = module.params
module.exit_json(
received={'url': params['url'], 'computers': params['computers']},
changed=True
)
if __name__ == '__main__':
main()
Run with this couple of tasks
- test_module:
url : 'htpp://xxxxx'
computers:
- a
- b
register: test
- debug:
var: test.received
This would yield:
TASK [test_module] ***********************************************************
changed: [localhost]
TASK [debug] *****************************************************************
ok: [localhost] =>
test.received:
computers:
- a
- b
url: htpp://xxxxx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |