IBM-Security / isam-ansible-roles

Ansible Custom Modules, Handlers and Tasks for ISAM. Requires "ibmsecurity" python package.
Apache License 2.0
24 stars 43 forks source link

set_host_records returns HTTP Error 400 if we try and update hostname/host_record #84

Open Franclaf7 opened 6 years ago

Franclaf7 commented 6 years ago

Hi Ram,

While trying to run a playbook to update the address for a hostname, we understandably get an HTTP Error 400 ("The specified hostname is already associated with another IP address in the hosts file").

We looked into what we could possibly change and we were wondering something. In the set_host_records role, there's a call to ibmsecurity.isam.base.host.records.set while the ibmsecurity.isam.base.network.host_records.set also exists and seems more complete (with add vs update possibility and all). So our question is this; is there a reason behind the coexistence of these two files (base/network/host_records.py and base/host/records.py)? Is there a change to be made in the role to call the more complete of the two?

Neither of those functions deal with what we are trying to do, while the API refuses to add the hostname/host record. We were wondering whether or not there was a possibility to work on a new "check existing/delete hostname from old record/add hostname to new host record" functions(s), or if you wanted to keep that logic out of the modules and in the API?

Follow up questions if we work on those new functions:

Thanks for your feedback,

Francis L.

ram-ibm commented 6 years ago

I am not sure why we have a hostname.py and a host_records.py - hoping @jldement can have a look. I would suggest update the role to use the most complete one.

I had to deal with that issue when adding host_records into ISAM. Actually I had to cleanup the set() function to handle it cleanly. I would like to keep the logic out of the python code to deal with the error "The specified hostname is already associated with another IP address in the hosts file". That goes beyond the realm of the REST API idempotency and looking at a layer beyond that. That I believe should be handled outside of the python code.

Franclaf7 commented 6 years ago

I tried using the _isam/base/network/hostrecords.py update() function (coming from the set() call in the role), but it returned a HTTP 400 Error (Invalid JSON).

return isamAppliance.invoke_post(
            "Update existing host record",
            "/isam/host_records/{0}/hostnames".format(addr),
            { 'name': hostnames_remaining[0] }
        )

Instead of " { 'name': hostnames_remaining[0] } ", I use " { 'name': hostnames_remaining[0]['name'] }" so that it really goes and get the hostname 'test.ca' instead of the whole key-value " { 'name': 'test.ca' } ".

With this fix, if I run a playbook, it sends me an HTTP 400 Error saying "The specified hostname is already associated with the specified IP address in the hosts file." so there seems to be something wrong with the idempotency of this function (The way I see it is, if it's already set, don't do anything and let the playbook run green as it usually does... I'm thinking it has to do with the fact that an update() function is making a POST call instead of a PUT call)

It is not the same error that we first had ("The specified hostname is already associated with another IP address in the hosts file").