New module return type

9 views
Skip to first unread message

matzeho...@web.de

unread,
Feb 4, 2018, 12:53:43 PM2/4/18
to Ansible Project
I'm currently developing my first ansible module. It can read/write os x settings, since these settings can be nested the return type can be an integer, float, string, dict, list, etc...
When I run the validate-modules test on the following documentation:
RETURN = '''
value:
    description: The value associated with the preference domain and key.
                 Return type is a python object that maps closest to the data type of the macOS preference. This can be an integer, float, string, dict, list, etc...
    returned: when action=get
    type: complex
    sample: "{'CustomViewStyleVersion': 1}"
'''

The test complains that I have to add the contains key. Because the output of my module differs based on which settings it reads, I can't specify the contains key.
I would be glad if someone could tell me how to solve this problem.

Thanks in advance!

Jordan Borean

unread,
Feb 4, 2018, 2:10:49 PM2/4/18
to Ansible Project
I don’t meant to burst your bubble but a module to do this already exists http://docs.ansible.com/ansible/latest/osx_defaults_module.html. It may be good to look into that and see if it does what you are looking to so. For this issue, complex usually means a rift type, you may be better off setting the type as a string and say in the description the type could change depending on the key. Unfortunately there isn’t an easy way to do what you are looking to do here.

Thanks

Jordan

matzeho...@web.de

unread,
Feb 4, 2018, 2:45:25 PM2/4/18
to Ansible Project
Thank you for your response!
Actually the osx_defaults module you are referring to is very limited in scope because the command it uses doesn't support nested dictionaries. My module manipulates these defaults in another way.
What do you mean by "rift type" ? I think I will follow you advice and declare the return type as string.

Jordan Borean

unread,
Feb 4, 2018, 6:04:25 PM2/4/18
to Ansible Project
Sorry was a typo that meant dict, I’m not really sure how macOS works but would it be better to add the dict support types to the existing module instead of creating a new one?
Reply all
Reply to author
Forward
0 new messages