networktocode / fortimanager-ansible

Ansible Modules to manage Fortinet FortiManager
Other
65 stars 34 forks source link

not working on v5.2.9 fortimanager #6

Closed bjolivot closed 6 years ago

bjolivot commented 7 years ago

Hello @jmcgill298 gerat work !

I have fresh fortimanager vm 5.2.9 and your modules are not working. Many times, you use

if not session_login.json()["result"][0]["status"]["code"] == 0:

And for me result is not a list, just a single dict. What's your env ?

I see lot of code duplication, don't you want to create a single module_util file and point to it with your modules ? I'm very interested in fortimanager with ansible, maybe I can help you ?

jmcgill298 commented 7 years ago

Hi @bjolivot thanks for pulling this down and testing it out. We appreciate the feedback.

Ideally we would have a module_utils file and a module_docs_fragment, but for now we keep these as part of each module for simplicity of use (just clone the repo, no installation required).

I used FortiManager 5.4 for my testing, and it very well could be a difference in expected output. Maybe we could add a type check to see if it is a list or a dict and then make the appropriate status code check. Can you see if change that this fixes it:

if type(session_login.json()["result"]) is dict:
    if not session_login.json()["result"][0]["status"]["code"] == 0:
        ...
elif not session_login.json()["result"]["status"]["code"] == 0:
...

We welcome suggestions and contributions, so feel free to continue raising issues and putting in pull requests.

jmcgill298 commented 7 years ago

@bjolivot have you been able to test the above solution? If so, how did it work?

hemskgren commented 6 years ago

please add documentaion about tested FortiManager version.

jmcgill298 commented 6 years ago

@hemskgren it is already documented here https://github.com/networktocode/fortimanager-ansible/blob/master/Module_Docs/fortimgr_module_docs.md

look under requirements at the top