infobloxopen / infoblox-ansible

Ansible modules for interfacing to Infoblox systems
GNU General Public License v3.0
54 stars 60 forks source link

Can't set DHCP Option 60 on a network object #25

Closed mrmac228 closed 2 years ago

mrmac228 commented 3 years ago

Trying to set DHCP Options via Ansible on a network.

Code is as follows:

Setting Option 43 works fine if the 2 lines for option 60 are commented out. If the 2 lines for option 60 are not commented out the following error is displayed:

TASK [infoblox : network for epg] *** fatal: [srviacp02]: FAILED! => {"changed": false, "code": "Client.Ibap.Proto", "msg": "Option vendor-class-identifier can not have a use_option flag", "operation": "update_object", "type": "AdmConProtoError"}

The following version are used: ansible 2.10.2 infoblox.nios_modules 1.0.0

TimS-sva commented 3 years ago

Hi a few more infos on this issue: in ansible_collections/infoblox/nios_modules/plugins/modules/nios_network.py

def check_vendor_specific_dhcp_option(module, ib_spec): 
    '''This function will check if the argument dhcp option belongs to vendor-specific and if yes then will remove 
     use_options flag which is not supported with vendor-specific dhcp options. 
    ''' 
    for key, value in iteritems(ib_spec): 
        if isinstance(module.params[key], list): 
            temp_dict = module.params[key][0] 
            if 'num' in temp_dict: 
                if temp_dict['num'] in (43, 124, 125): 
                    del module.params[key][0]['use_option'] 
    return ib_spec 

it seems that if you run the module with more than one dhcp option defined this will not remove the use_option. I have tried it to insert the num vaules there.

I have found a solution mentioned in the infoblox forum: https://community.infoblox.com/t5/API-Integration/Bug-in-Ansible-2-8-with-options-in-nios-fixed-address/td-p/18842

if you add this

def options(module): 
    ''' Transforms the module argument into a valid WAPI struct 
    This function will transform the options argument into a structure that 
    is a valid WAPI structure in the format of: 
        { 
            name: <value>, 
            num: <value>, 
            value: <value>, 
            use_option: <value>, 
            vendor_class: <value> 
        } 
    It will remove any options that are set to None since WAPI will error on 
    that condition.  It will also verify that either `name` or `num` is 
    set in the structure but does not validate the values are equal. 
    The remainder of the value validation is performed by WAPI 
    ''' 
    special_options = {'routers': 3, 'router-templates': 1, 'domain-name-servers': 6, 
                       'domain-name': 15, 'broadcast-address': 28, 'broadcast-address-offset': 1, 
                       'dhcp-lease-time': 51, 'dhcp6.name-servers': 23} 
    options = list() 
    for item in module.params['options']: 
        opt = dict([(k, v) for k, v in iteritems(item) if v is not None]) 
        if 'name' not in opt and 'num' not in opt: 
            module.fail_json(msg='one of `name` or `num` is required for option value') 
        if 'name' not in special_options.keys() or 'num' not in special_options.values(): 
            del opt['use_option'] 
        options.append(opt) 
    return options 

the module worked fine for me

megabreit commented 3 years ago

To me it looks like the fix https://github.com/ansible/ansible/pull/67924 was never added to some stable release and is now not in the Ansible repo anymore. It probably got moved out... but unfortunately not to the Infoblox repo. I'm not familiar with the new Ansible source yet... maybe the old fixes are somewhere... Can you check if this fix is also fixing your issue? We could add a new PR then to fix it here.

TimS-sva commented 3 years ago

Hi @megabreit sorry don't understand. I described the solution that worked for me the fix that you mentioned is in another module. I lookd in the actual version of infoblox.nios_modules:1.0.2 and specific the nios_network.py. In the Issue menthioined i used the collection from Red Hat Automation Hub but i don't know if there is a difference between Automation Hub and ansible-galaxy direct.

megabreit commented 3 years ago

Hi @TimS-sva my original fix was intended for nios_fixed_address.py... and I didn't notice that you used the same fix in a different file nios_network.py. My bad. To summarize: Both nios_fixed_address.py and nios_network.py need to be patched. But since no developer is reading this issue, I doubt that they would act on a PR. To the devs: Otherwise please suggest how to continue here!

TimS-sva commented 3 years ago

Hi @megabreit We opend a PR and the answer was to open the issue on github and @mrmac228 has done it. But i don't see any changes. I used to solve the problem for me a copy of the collection with the mentioned fix in it.

Maciejzzzz commented 2 years ago

In case of network module I would take different approach, the 'use_option' should only be used for a few options that are preconfigured in the Infoblox GUI with Inherited option on them.