infobloxopen / infoblox-ansible

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

feat: Grid Master Candidate, Nios Range and Network member assignment #152

Closed matthewdennett closed 1 year ago

matthewdennett commented 1 year ago

This PR aims to provide the support for 3 new feature

  1. Member assignment during the creation of a network with the niso_network module.
  2. Configuration of a nios member as a Grid Master Candidate with the nios_member module.
  3. Configuration of Nios Network DHCP ranges with the nios_range module

This PR combines the changes proposed in PR #145 and #151 to simplify the merge and prevent conflicts.

Support for Member Assignment

To support this change 'convert_members_to_struct(member_spec)' has been added to 'module_utils/api.py' that transforms the ansible input into the correct data structure required for the API endpoint. With this transformation the existing process can now successfully create the member assignment and update the assignment if needed.

This will address feature request: https://github.com/infobloxopen/infoblox-ansible/issues/69

Grid Master Candidate Support

This has been achieved with a minor change to the 'modules/nios_member.py' to add the additional parameter to the ib_spec dict.

This will address feature request: https://github.com/infobloxopen/infoblox-ansible/issues/148

Nios Range

To support this change 'def convert_range_member_to_struct(member_spec):' has been added to 'module_utils/api.py' that transforms the ansible input into the correct data structure required for the API endpoint and sets the 'server_association_type' option to the associated value. With this transformation the existing process can now successfully create the network range .

ranjishmp commented 1 year ago

@matthewdennett Code wise everything looks fine. QA team will validate this soon

matthewdennett commented 1 year ago

@hemanthKa677 I have just pushed a commit to include an example paly.

matthewdennett commented 1 year ago

Hi @hemanthKa677,

I am unable to recreate the error yo have mentioned. Can you please provide the steps you took and the playbook you ran when you received the error?

Here is the playbook that I have been using for testing.

---
- name: Testing GMC Members
  hosts: localhost
  connection: local
  tasks:
    - name: Configure a member as a GMC
      infoblox.nios_modules.nios_member:
        host_name: member03.localdomain
        config_addr_type: ### IPV4
        platform: VNIOS
        comment: "Created by Ansible"
        master_candidate: true
        state: present
        vip_setting:
          - address: 192.168.1.104
            subnet_mask: 255.255.255.0
            gateway: 192.168.1.1
        provider:
          host: "10.1.1.200"
          password: "infoblox"
          username: "admin"
          validate_certs: false
          wapi_version: "2.12"
      connection: local

I have tested this on my local copy, a fresh clone from matthewdennett:infoblox-ansible and to make sure the error hasn't been introduced from other recent changes to the repo I have tested again after rebasing off infoblox:master. In all cases I was not able to reproduce the error and the task is working as expected.

If you do a ansible-playbook -vvv is the task being invoked 'ipv6_setting' set to null when not defined? This is what i'm getting...

ok: [localhost] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "comment": "Created by Ansible",
            "config_addr_type": "IPV4",
            "create_token": false,
            "enable_ha": false,
            "extattrs": null,
            "external_syslog_server_enable": null,
            "host_name": "member03.localdomain",
            "ipv6_setting": null,
            "lan2_enabled": false,
            "lan2_port_setting": null,
            "master_candidate": true,
            "mgmt_port_setting": null,
            "node_info": null,
            "platform": "VNIOS",
            "pre_provisioning": null,
            "provider": {
                "cert": null,
                "host": "10.1.1.200",
                "http_pool_connections": 10,
                "http_pool_maxsize": 10,
                "http_request_timeout": 10,
                "key": null,
                "max_results": 1000,
                "max_retries": 3,
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "silent_ssl_warnings": true,
                "username": "admin",
                "validate_certs": false,
                "wapi_version": "2.12"
            },
            "router_id": null,
            "state": "present",
            "syslog_servers": null,
            "upgrade_group": "Default",
            "use_syslog_proxy_setting": null,
            "vip_setting": [
                {
                    "address": "192.168.1.104",
                    "gateway": "192.168.1.1",
                    "subnet_mask": "255.255.255.0"
                }
            ]
        }
    }
}
matthewdennett commented 1 year ago

Hi @hemanthKa677,

Is there anything outstanding on this PR that I need to address before it's merged? I saw a few other PR merged the other day but there has been no progress on this one.

matthewdennett commented 1 year ago

Hey @hemanthKa677 can we give this one another poke?

matthewdennett commented 1 year ago

Hey @hemanthKa677 @Vaishnavi-infoblox @anagha-infoblox, Do we have any updates on when this can be merged?

matthewdennett commented 1 year ago

Hi @hemanthKa677,

I think that I have resolved all of the above issues found by the QA team. Please have the changes reviewed and let me know how it goes.

hemanthKa677 commented 1 year ago

Hi @hemanthKa677,

I think that I have resolved all of the above issues found by the QA team. Please have the changes reviewed and let me know how it goes.

hemanthKa677 commented 1 year ago

Hi @matthewdennett , Could you please double check for this regression issue here below? https://github.com/infobloxopen/infoblox-ansible/pull/152#pullrequestreview-1337029853 because it still exists with nios_member.

matthewdennett commented 1 year ago

Hi @hemanthKa677,

I have added the change you suggested and run a few test to confirm that is now working to update a range in a network view.

Hi @matthewdennett , Could you please double check for this regression issue here below? #152 (review) because it still exists with nios_member.

Can you clarify the issues that you referring to in the above comment? I have just verified that re running a the same task is returning the expected changed: false value when assigning a member to a network. Here are the json args that I have passed into nios_network.py for testing.

{
    "ANSIBLE_MODULE_ARGS": {
    "network": "192.168.10.0/24",
    "comment": "This is a test comment",
    "members": [
            { "name": "infoblox.localdomain" }
        ],
    "state": "present",
    "network_view": "test",
    "provider": {
        "host": "10.1.1.201",
        "username": "admin",
        "password": "infoblox",
        "wapi_version": "2.12"
        }
    }
}

And here is the output as showing the second execution returned changed: false

(venv) matt@box:~/.ansible/collections/ansible_collections/infoblox/nios_modules$ python3 plugins/modules/nios_network.py network_args.yml 
{"changed": true, "invocation": {"module_args": {"network": "192.168.10.0/24", "comment": "This is a test comment", "members": [{"name": "********.localdomain"}], "state": "present", "network_view": "test", "provider": {"host": "10.1.1.201", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "wapi_version": "2.12", "validate_certs": false, "silent_ssl_warnings": true, "http_request_timeout": 10, "http_pool_connections": 10, "http_pool_maxsize": 10, "max_retries": 3, "max_results": 1000, "cert": null, "key": null}, "options": null, "template": null, "extattrs": null, "container": null}}}

(venv) matt@box:~/.ansible/collections/ansible_collections/infoblox/nios_modules$ python3 plugins/modules/nios_network.py network_args.yml 
{"changed": false, "invocation": {"module_args": {"network": "192.168.10.0/24", "comment": "This is a test comment", "members": [{"name": "********.localdomain"}], "state": "present", "network_view": "test", "provider": {"host": "10.1.1.201", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "wapi_version": "2.12", "validate_certs": false, "silent_ssl_warnings": true, "http_request_timeout": 10, "http_pool_connections": 10, "http_pool_maxsize": 10, "max_retries": 3, "max_results": 1000, "cert": null, "key": null}, "options": null, "template": null, "extattrs": null, "container": null}}}
hemanthKa677 commented 1 year ago

Hi @matthewdennett , I will make it clear, the issue is not with re run playbook for member assignment to a network. The issue is with creating member

tasks:
   - name: add a member to the grid with IPv4 address
     infoblox.nios_modules.nios_member:
       host_name: block1.localdomain
       vip_setting:
         - address: 120.0.0.25
           subnet_mask: 255.255.255.0
           gateway: 120.0.0.1
       config_addr_type: IPV4
       platform: INFOBLOX
       comment: Created with Ansible
       extattrs: {'Site':'HQ'}
       state: present
       provider: "{{ nios_provider }}"

If I am trying to re run this playbook, it was showing the changed status as true, where it should throw false as output. Please look into this and see you can add some fix.

matthewdennett commented 1 year ago

Hi @hemanthKa677,

Thanks for clarifying. I have pushed a change to address the idempotence issue you mention.

This bug has surfaced due to the fix I added to the compare_objects function. It was incorrectly returning early before evaluating all elements of the object when an element was a dict. It's very possible this will also address some other issues that would arise as a result of the incorrect object comparison.