diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 2e29d4ba..0d14379b 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -13,15 +13,15 @@ jobs: strategy: fail-fast: false matrix: - ansible-version: [stable-2.10] + ansible-version: [stable-2.14] steps: - name: Check out code uses: actions/checkout@v2 - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: '3.10' - name: Install ansible (${{ matrix.ansible-version }}) run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check @@ -34,7 +34,7 @@ jobs: with: name: collection path: .cache/collection-tarballs - + ### # Unit tests @@ -48,15 +48,21 @@ jobs: strategy: fail-fast: false matrix: - python-version: [2.7, 3.8, 3.9] - ansible-version: [stable-2.9, stable-2.10, stable-2.11, stable-2.12, devel] + python-version: ['3.8', '3.9', '3.10', '3.11'] + ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] exclude: - ansible-version: devel - python-version: 2.7 - - ansible-version: stable-2.12 - python-version: 2.7 - - ansible-version: stable-2.9 - python-version: 3.9 + python-version: '3.8' + - ansible-version: devel + python-version: '3.9' + - ansible-version: stable-2.16 + python-version: '3.8' + - ansible-version: stable-2.16 + python-version: '3.9' + - ansible-version: stable-2.15 + python-version: '3.8' + - ansible-version: stable-2.14 + python-version: '3.8' steps: - name: Set up Python ${{ matrix.python-version }} @@ -76,8 +82,8 @@ jobs: - name: Setup Unit test Pre-requisites run: | ansible-galaxy collection install .cache/collection-tarballs/*.tar.gz - git clone https://github.com/ansible/ansible.git - cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/ + git clone https://github.com/ansible/ansible.git -b ${{ matrix.ansible-version }} + if [ "${{ matrix.ansible-version }}" != "devel" ]; then cp -rf ansible/test/units/compat /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/; fi cp -rf ansible/test/units/modules/utils.py /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/ sed -i 's/units/ansible_collections.infoblox.nios_modules.tests.unit/' /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py if [ -f /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt ]; then pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt; fi @@ -87,7 +93,11 @@ jobs: - name: Generate coverage report run: | - if [ "${{ matrix.ansible-version }}" == "devel" ]; then pip install coverage==6.3.2; fi + if [ "${{ matrix.ansible-version }}" == "stable-2.14" ]; then + pip install coverage==6.5.0; + elif [ "${{ matrix.ansible-version }}" == "stable-2.15" ]; then + pip install coverage==6.5.0; + fi ansible-test coverage xml -v --group-by command --group-by version working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/ @@ -104,16 +114,31 @@ jobs: strategy: fail-fast: false matrix: - python-version: [2.7, 3.8, 3.9] - ansible-version: [stable-2.9, stable-2.10, stable-2.11, stable-2.12, devel] + python-version: ['3.8', '3.9', '3.10', '3.11'] + ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] exclude: - - ansible-version: stable-2.9 - python-version: 3.9 + - ansible-version: devel + python-version: '3.8' + - ansible-version: devel + python-version: '3.9' + - ansible-version: stable-2.16 + python-version: '3.8' + - ansible-version: stable-2.16 + python-version: '3.9' + - ansible-version: stable-2.15 + python-version: '3.8' + - ansible-version: stable-2.14 + python-version: '3.8' steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Check out code uses: actions/checkout@v2 - - name: Install ansible-base (${{ matrix.ansible }}) + - name: Install ansible-base (${{ matrix.ansible-version }}) run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check - name: Download migrated collection artifacts @@ -121,12 +146,14 @@ jobs: with: name: collection path: .cache/collection-tarball - + - name: Install the collection tarball run: ansible-galaxy collection install .cache/collection-tarball/*.tar.gz - + - name: Setup Integration test Pre-requisites - run: pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/requirements.txt + run: | + sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0 + pip install -r /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/tests/requirements.txt # Run the integration tests - name: Run integration test @@ -134,7 +161,7 @@ jobs: echo $ANSIBLE_NIOSSIM_CONTAINER ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python-version }} --docker --coverage env: - ANSIBLE_NIOSSIM_CONTAINER: quay.io/ansible/nios-test-container:1.4.0 + ANSIBLE_NIOSSIM_CONTAINER: quay.io/ansible/nios-test-container:3.0.0 working-directory: /home/runner/.ansible/collections/ansible_collections/infoblox/nios_modules/ # ansible-test support producing code coverage date @@ -145,8 +172,8 @@ jobs: - uses: codecov/codecov-action@v1 with: fail_ci_if_error: false - - + + ### # Sanity tests (REQUIRED) # @@ -159,15 +186,15 @@ jobs: strategy: fail-fast: false matrix: - ansible-version: [stable-2.9, stable-2.10, stable-2.11, stable-2.12, devel] + ansible-version: [stable-2.14, stable-2.15, stable-2.16, devel] steps: - - name: Set up Python 3.8 + - name: Set up Python 3.10 uses: actions/setup-python@v1 with: # it is just required to run that once as "ansible-test sanity" in the docker image # will run on all python versions it supports. - python-version: 3.8 + python-version: '3.10' - name: Install ansible (${{ matrix.ansible-version }}) version run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check diff --git a/.gitignore b/.gitignore index 7bbc71c0..ce7914c2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ # Distribution / packaging .Python env/ +.direnv/ build/ develop-eggs/ dist/ @@ -99,3 +100,10 @@ ENV/ # mypy .mypy_cache/ +infoblox-ansible.code-workspace + +# Ansible sanity test ouput +**/ansible-test-sanity-*.json + +# Dev tools +.vscode/ diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b8523d74..b4941d31 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,144 @@ Infoblox.Nios_Modules Release Notes =================================== .. contents:: Topics +v1.6.1 +====== + +Release Summary +--------------- +This release includes the updates of plug-in version 1.6.0 and the following documentation changes: +Ansible core version in the dependencies updated to 2.14 or later. + +Minor Changes +------------- +Ansible core version in the dependencies updated to 2.14 or later. + +v1.6.0 +====== + +Release Summary +--------------- +Added new modules with CRUD features to manage NIOS DTC health check monitors: DTC HTTP Monitor, +DTC ICMP Monitor, DTC PDP Monitor, DTC SIP Monitor, DTC SNMP Monitor, DTC TCP Monitor. +Added a new module with CRUD features to manage topology rulesets in NIOS. +Added a new field to define topology ruleset for the DTC Pool and DTC LBDN modules. + +Major Changes +------------- +- Upgrade Ansible version support from 2.13 to 2.16. +- Upgrade Python version support from 3.8 to 3.10. + +New Modules +----------- +- infoblox.nios_modules.nios_dtc_monitor_http - Configures the Infoblox NIOS DTC HTTP monitor +- infoblox.nios_modules.nios_dtc_monitor_icmp - Configures the Infoblox NIOS DTC ICMP monitor +- infoblox.nios_modules.nios_dtc_monitor_pdp - Configures the Infoblox NIOS DTC PDP monitor +- infoblox.nios_modules.nios_dtc_monitor_sip - Configures the Infoblox NIOS DTC SIP monitor +- infoblox.nios_modules.nios_dtc_monitor_snmp - Configures the Infoblox NIOS DTC SNMP monitor +- infoblox.nios_modules.nios_dtc_monitor_tcp - Configures the Infoblox NIOS DTC TCP monitor +- infoblox.nios_modules.nios_dtc_topology - Configures the Infoblox NIOS DTC Topology + +Bugfixes +--------- +- Fixes typo for environment variable INFOBLOX_WAPI_VERSION `#209 `_ +- Fixes environment variable max_results using INFOBLOX_MAX_RESULTS `#209 `_ +- Fixes index error for transform fields in DTC LBDN (auth_zone and Pool) and DTC POOL (servers and monitors) `#209 `_ + +v1.5.0 +====== + +Release Summary +--------------- +- Added new module - NIOS Range with Create, Update and Delete features +- Added new feature - Member Assignment to Networks with add and remove functionality +- Fixes Unable to Update/Delete EAs using Ansible plugin +- Fixes Static Allocation of IPV4 address of A Record +- Updates default WAPI version to 2.9 +- Added Grid Master Candidate feature + +Major Changes +------------- +- Added NIOS Range module with Create, Update and Delete features `#152 `_ +- Added Member Assignment to network and ranges `#152 `_ +- Added Grid Master Candidate feature `#152 `_ +- Fixes issue unable to update/delete EAs using Ansible plugin `#180 `_ +- Fixes static and dynamic allocation of IPV4 address of A Record `#182 `_ +- Fixes to Update host name of NIOS member `#176 `_ +- Updates default WAPI version to 2.9 `#176 `_ + +Bugfixes +--------- +- Fixes Update A Record having multiple records with same name and different IP `#182 `_ + + +v1.4.1 +====== + +Release Summary +--------------- +- Ansible Lookup modules can specify network_view to which a network/ip belongs +- Fixes camelCase issue while updating 'nios_network_view' with 'new_name' +- Fixes issue to allocate ip to a_record dynamically +- Updates 'nios_a_record' name with multiple ips having same name + +Minor Changes +------------- +- Fix to specify network_view in lookup modules to return absolute network/ip `#157 `_ +- Fix to camelcase issue for updating 'nios_network_view' name `#163 `_ +- Fix to allocate ip to a_record dynamically `#163 `_ +- Fix to update 'nios_a_record' name with multiple ips having same name `#164 `_ +- Fix to changelog yaml file with linting issues `#161 `_ + + +v1.4.0 +====== + +Release Summary +--------------- +- For ansible module, added certificate authentication feature +- Few bug fixes in ansible module nios network + +Major Changes +------------- +- Feature for extra layer security, with `cert` and `key` parameters in playbooks for authenticating using certificate and key .pem file absolute path `#154 ` +- Fix to remove issue causing due to template attr in deleting network using Ansible module nios network `#147 `_ + + +v1.3.0 +====== + +Release Summary +--------------- +- Issue fixes to create TXT record with equals sign +- For nonexistent record, update operation creates the new record +- For nonexistent IPv4Address, update operation creates a new A record with new_ipv4addr + +Major Changes +------------- +- Update operation using `old_name` and `new_name` for the object with dummy name in `old_name` (which does not exist in system) will not create a new object in the system. An error will be thrown stating the object does not exist in the system `#129 `_ +- Update `text` field of TXT Record `#128 `_ + +Bugfixes +--------- +- Fix to create TXT record with equals sign `#128 `_ + + +v1.2.2 +====== + +Release Summary +--------------- +- Issue fixes to create PTR record in different network views +- Support extended to determine whether the DTC server is disabled or not + +Minor Changes +------------- +- Fix to create PTR record in different network views `#103 `_ +- Remove use_option for DHCP option 60 `#104 `_ +- Allow specifying a template when creating a network `#105 `_ +- Fix unit and sanity test issues `#117 `_ +- Expanding for disable value `#119 `_ + v1.2.1 ====== diff --git a/README.md b/README.md index eab59542..17bd1c58 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,24 @@ Modules - `nios_dtc_lbdn` – Configure Infoblox NIOS DTC LBDN records +- `nios_dtc_monitor_http` – Configure Infoblox NIOS DTC HTTP monitors + +- `nios_dtc_monitor_icmp` – Configure Infoblox NIOS DTC ICMP monitors + +- `nios_dtc_monitor_pdp` – Configure Infoblox NIOS DTC PDP monitors + +- `nios_dtc_monitor_sip` – Configure Infoblox NIOS DTC SIP monitors + +- `nios_dtc_monitor_snmp` – Configure Infoblox NIOS DTC SNMP monitors + +- `nios_dtc_monitor_tcp` – Configure Infoblox NIOS DTC TCP monitors + - `nios_dtc_pool` – Configure Infoblox NIOS DTC pools - `nios_dtc_server` – Configure Infoblox NIOS DTC server records +- `nios_dtc_topology` – Configure Infoblox NIOS DTC topologies + - `nios_fixed_address` – Configure Infoblox NIOS DHCP Fixed Address - `nios_host_record` – Configure Infoblox NIOS host records @@ -59,6 +73,8 @@ Modules - `nios_ptr_record` – Configure Infoblox NIOS PTR records +- `nios_range` - Configure Infoblox NIOS Network Range object + - `nios_restartservices` - Controlled restart of Infoblox NIOS services - `nios_srv_record` – Configure Infoblox NIOS SRV records @@ -85,11 +101,15 @@ Installation Dependencies ------------ -- Python version 2.7 or later +- Python version 3.10 or later + +- Ansible Core version 2.14 or later -- Ansible version 2.9.0 or later +- NIOS 8.6.x and 9.0.x -- NIOS 8.2.4 or later +- Infoblox WAPI version 2.9 or later + +Note: For modules of DTC objects to function properly, Infoblox recommends WAPI version 2.12 or later. Prerequisites ------------- @@ -172,7 +192,7 @@ Dates TBD Current release --------------- -1.2.1 on 21 December 2021 +1.6.1 on 19 Dec 2023 Versioning ========= diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml index 39f2ec84..3ed1f4b5 100644 --- a/changelogs/.plugin-cache.yaml +++ b/changelogs/.plugin-cache.yaml @@ -59,6 +59,41 @@ plugins: name: nios_dtc_server namespace: '' version_added: 1.1.0 + nios_dtc_monitor_http: + description: Configure Infoblox NIOS DTC HTTP monitor + name: nios_dtc_monitor_http + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_tcp: + description: Configure Infoblox NIOS DTC TCP monitor + name: nios_dtc_monitor_tcp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_icmp: + description: Configure Infoblox NIOS DTC ICMP monitor + name: nios_dtc_monitor_icmp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_pdp: + description: Configure Infoblox NIOS DTC PDP monitor + name: nios_dtc_monitor_pdp + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_sip: + description: Configure Infoblox NIOS DTC SIP monitor + name: nios_dtc_monitor_sip + namespace: '' + version_added: 1.6.0 + nios_dtc_monitor_snmp: + description: Configure Infoblox NIOS DTC SNMP monitor + name: nios_dtc_monitor_snmp + namespace: '' + version_added: 1.6.0 + nios_dtc_topology: + description: Configure Infoblox NIOS DTC Topology + name: nios_dtc_topology + namespace: '' + version_added: 1.6.0 nios_fixed_address: description: Configure Infoblox NIOS DHCP Fixed Address name: nios_fixed_address @@ -128,4 +163,4 @@ plugins: shell: {} strategy: {} vars: {} -version: 1.2.1 +version: 1.6.1 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 2ef56dff..ec67aff0 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -113,11 +113,10 @@ releases: - Sanity fixes as per Ansible guidelines to all modules minor_changes: - The modules are standardized as per Ansible guidelines - release_summary: - - Support for creating IPv6 Fixed Address with DUID - - Support added to return the next available IP address for an IPv6 network - - Modules made compatible to work with ansible-core 2.11 - - Issue fixes and standardization of modules as per Ansible guidelines + release_summary: 'Support for creating IPv6 Fixed Address with DUID, + Support added to return the next available IP address for an IPv6 network, + Modules made compatible to work with ansible-core 2.11, + Issue fixes and standardization of modules as per Ansible guidelines' release_date: '2021-09-07' 1.1.2: changes: @@ -127,9 +126,8 @@ releases: minor_changes: - Changes in inventory and lookup plugins documentation `#85 `_ - Directory restructure and added integration & unit tests `#87 `_ - release_summary: - - Issue fixes and standardization of inventory plugin and lookup modules as per Ansible guidelines - - Directory restructure and added integration & unit tests + release_summary: 'Issue fixes and standardization of inventory plugin and lookup modules as per Ansible guidelines, + Directory restructure and added integration & unit tests' release_date: '2021-10-12' 1.2.0: changes: @@ -146,14 +144,119 @@ releases: | CNAME | canonical | | MX | mail_exchanger, preference | | PTR | ptrdname | - release_summary: - - Issue fixes to update A Record using 'next_available_ip' function - - Added a new feature - Update canonical name of the CNAME Record - - Updated the 'required' fields in modules + release_summary: 'Issue fixes to update A Record using `next_available_ip` function, + Added a new feature - Update canonical name of the CNAME Record, + Updated the `required` fields in modules' release_date: '2021-12-13' 1.2.1: changes: minor_changes: - Added tags 'cloud' and 'networking' in 'galaxy.yaml' - release_summary: Added tags to support release on Ansible Automation Hub + release_summary: 'Added tags to support release on Ansible Automation Hub' release_date: '2021-12-20' + + 1.2.2: + changes: + minor_changes: + - Fix to create PTR record in different network views `#103 `_ + - Remove use_option for DHCP option 60 `#104 `_ + - Allow specifying a template when creating a network `#105 `_ + - Fix unit and sanity test issues `#117 `_ + - Expanding for disable value `#119 `_ + release_summary: 'Issue fixes to create PTR record in different network views, + Support extended to determine whether the DTC server is disabled or not' + release_date: '2022-05-23' + 1.3.0: + changes: + major_changes: + - Update operation using `old_name` and `new_name` for the object with dummy name in `old_name` (which does not exist in system) will not create a new object in the system. An error will be thrown stating the object does not exist in the system `#129 `_ + - Update `text` field of TXT Record `#128 `_ + bugfixes: + - Fix to create TXT record with equals sign `#128 `_ + release_summary: 'Issue fixes to create TXT record with equals sign, + For nonexistent record, update operation creates the new record, + For nonexistent IPv4Address, update operation creates a new A record with new_ipv4addr' + release_date: '2022-07-01' + 1.4.0: + changes: + major_changes: + - Feature for extra layer security , with `cert` and `key` parameters in playbooks for authenticating using certificate and key ``*.pem`` file absolute path `#154 `_ + - Fix to remove issue causing due to template attr in deleting network using Ansible module nios network `#147 `_ + release_summary: 'For ansible module, added certificate authentication feature, + Few bugs fix in ansible module nios network' + release_date: '2022-10-12' + 1.4.1: + changes: + minor_changes: + - Fix to specify network_view in lookup modules to return absolute network and ip `#157 `_ + - Fix to camelcase issue for updating 'nios_network_view' name `#163 `_ + - Fix to allocate ip to a_record dynamically `#163 `_ + - Fix to update 'nios_a_record' name with multiple ips having same name `#164 `_ + - Fix to changelog yaml file with linting issues `#161 `_ + release_summary: 'Ansible Lookup modules can specify network_view to which a network/ip belongs, + Fixes camelCase issue while updating `nios_network_view` with `new_name`, + Fixes issue to allocate ip to a_record dynamically, + Updates `nios_a_record` name with multiple ips having same name' + release_date: '2022-11-24' + 1.5.0: + changes: + major_changes: + - Added NIOS Range module with Create, Update and Delete features `#152 `_ + - Added Member Assignment to network and ranges `#152 `_ + - Added Grid Master Candidate feature `#152 `_ + - Fixes issue unable to update/delete EAs using Ansible plugin `#180 `_ + - Fixes static and dynamic allocation of IPV4 address of A Record `#182 `_ + - Fixes to Update host name of NIOS member `#176 `_ + - Updates default WAPI version to 2.9 `#176 `_ + bugfixes: + - Fixes Update A Record having multiple records with same name and different IP `#182 `_ + release_summary: 'Added new module NIOS Range with Create, Update and Delete features, + Added new feature Member Assignment to Networks with add and remove functionality, + Fixes Unable to Update/Delete EAs using Ansible plugin, + Fixes Static Allocation of IPV4 address of A Record, + Updates default WAPI version to `2.9`, + Added Grid Master Candidate feature' + release_date: '2023-05-11' + 1.6.0: + changes: + major_changes: + - Upgrade Ansible version support from 2.13 to 2.16. + - Upgrade Python version support from 3.8 to 3.10. + release_summary: 'Added new modules with CRUD features to manage NIOS DTC health check monitors: DTC HTTP Monitor, + DTC ICMP Monitor, DTC PDP Monitor, DTC SIP Monitor, DTC SNMP Monitor, DTC TCP Monitor. + Added a new module with CRUD features to manage topology rulesets in NIOS. + Added a new field to define topology ruleset for the DTC Pool and DTC LBDN modules.' + bugfixes: + - Fixes typo for environment variable INFOBLOX_WAPI_VERSION `#209 `_ + - Fixes environment variable max_results using INFOBLOX_MAX_RESULTS `#209 `_ + - Fixes index error for transform fields in DTC LBDN (auth_zone and Pool) and DTC POOL (servers and monitors) `#209 `_ + modules: + - description: Configures the Infoblox NIOS DTC HTTP monitor. + name: nios_dtc_monitor_http + namespace: '' + - description: Configures the Infoblox NIOS DTC ICMP monitor + name: nios_dtc_monitor_icmp + namespace: '' + - description: Configures the Infoblox NIOS DTC PDP monitor + name: nios_dtc_monitor_pdp + namespace: '' + - description: Configures the Infoblox NIOS DTC SIP monitor + name: nios_dtc_monitor_sip + namespace: '' + - description: Configures the Infoblox NIOS DTC SNMP monitor + name: nios_dtc_monitor_snmp + namespace: '' + - description: Configures the Infoblox NIOS DTC TCP monitor + name: nios_dtc_monitor_tcp + namespace: '' + - description: Configures the Infoblox NIOS DTC Topology + name: nios_dtc_topology + namespace: '' + release_date: '2023-12-14' + 1.6.1: + changes: + minor_changes: + - Ansible core version in the dependencies updated to 2.14 or later. + release_summary: 'This release includes the updates of plug-in version 1.6.0 and the following documentation changes: + Ansible core version in the dependencies updated to 2.14 or later.' + release_date: '2023-12-19' diff --git a/galaxy.yml b/galaxy.yml index 529578ce..787065d8 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,7 @@ namespace: infoblox name: nios_modules # The version of the collection. Must be compatible with semantic versioning -version: 1.2.1 +version: 1.6.1 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md @@ -17,10 +17,9 @@ readme: README.md # A list of the collection's content authors. Can be just the name or in the format 'Full Name (url) # @nicks:irc/im.site#channel' authors: -- Sailesh Giri (sgiri@infoblox.com) -- Vaishnavi TR (vtr@infoblox.com) -- Anagha KH (akh@infoblox.com) -- Shankar Ganesh (sganesh@infoblox.com) +- Hemanth Kumar (hkumar3@infoblox.com) +- Jeenitkumar Khatri (jkhatri@infoblox.com) +- Jaykumar Chhatbar (jchhatbar@infoblox.com) ### OPTIONAL but strongly recommended @@ -51,13 +50,13 @@ tags: #dependencies: {} # The URL of the originating SCM repository -repository: https://github.com/infobloxopen/infoblox-ansible +repository: https://github.com/infobloxopen/infoblox-ansible/tree/master # The URL to any online docs documentation: https://github.com/infobloxopen/infoblox-ansible/blob/master/README.md # The URL to the homepage of the collection/project -homepage: https://github.com/infobloxopen/infoblox-ansible/tree/master/ansible_collections/infoblox/nios_modules +homepage: https://github.com/infobloxopen/infoblox-ansible # The URL to the collection issue tracker issues: https://github.com/infobloxopen/infoblox-ansible/issues diff --git a/meta/runtime.yml b/meta/runtime.yml index 2ee3c9fa..be99ccf4 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,2 +1,2 @@ --- -requires_ansible: '>=2.9.10' +requires_ansible: '>=2.14.0' diff --git a/playbooks/create_dtc_monitor_http.yaml b/playbooks/create_dtc_monitor_http.yaml new file mode 100644 index 00000000..2d2afc3e --- /dev/null +++ b/playbooks/create_dtc_monitor_http.yaml @@ -0,0 +1,19 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC HTTPS monitor Test + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_icmp.yaml b/playbooks/create_dtc_monitor_icmp.yaml new file mode 100644 index 00000000..f792cfa6 --- /dev/null +++ b/playbooks/create_dtc_monitor_icmp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC ICMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_pdp.yaml b/playbooks/create_dtc_monitor_pdp.yaml new file mode 100644 index 00000000..ea2bc9b9 --- /dev/null +++ b/playbooks/create_dtc_monitor_pdp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC PDP monitor Test + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_sip.yaml b/playbooks/create_dtc_monitor_sip.yaml new file mode 100644 index 00000000..4caa32ea --- /dev/null +++ b/playbooks/create_dtc_monitor_sip.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC SIP monitor Test + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_snmp.yaml b/playbooks/create_dtc_monitor_snmp.yaml new file mode 100644 index 00000000..b8b796ee --- /dev/null +++ b/playbooks/create_dtc_monitor_snmp.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC SNMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_monitor_tcp.yaml b/playbooks/create_dtc_monitor_tcp.yaml new file mode 100644 index 00000000..95a824a1 --- /dev/null +++ b/playbooks/create_dtc_monitor_tcp.yaml @@ -0,0 +1,18 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Create Nios DTC TCP monitor Test + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/create_dtc_topology.yml b/playbooks/create_dtc_topology.yml new file mode 100644 index 00000000..01c50bd4 --- /dev/null +++ b/playbooks/create_dtc_topology.yml @@ -0,0 +1,31 @@ +--- +- hosts: localhost + vars: + nios_provider: + host: 10.196.205.10 + username: cloudadmin + password: infoblox + wapi_version: "2.12" + + connection: local + tasks: + - name: Create a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool1 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC1 + - dest_type: POOL + destination_link: web_pool2 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC2 + state: present + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_cname_record.yaml b/playbooks/delete_cname_record.yaml index 50c55105..f7f753a7 100644 --- a/playbooks/delete_cname_record.yaml +++ b/playbooks/delete_cname_record.yaml @@ -9,7 +9,7 @@ connection: local tasks: - - name: Create Nios CNAME record + - name: Delete Nios CNAME record infoblox.nios_modules.nios_cname_record: name: cname.ansible.com canonical: realhost.ansible.com diff --git a/playbooks/delete_dtc_monitor_http.yaml b/playbooks/delete_dtc_monitor_http.yaml new file mode 100644 index 00000000..29427ebd --- /dev/null +++ b/playbooks/delete_dtc_monitor_http.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC HTTPS monitor Test + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_icmp.yaml b/playbooks/delete_dtc_monitor_icmp.yaml new file mode 100644 index 00000000..eca2975f --- /dev/null +++ b/playbooks/delete_dtc_monitor_icmp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC ICMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_pdp.yaml b/playbooks/delete_dtc_monitor_pdp.yaml new file mode 100644 index 00000000..b69fb462 --- /dev/null +++ b/playbooks/delete_dtc_monitor_pdp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC PDP monitor Test + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_sip.yaml b/playbooks/delete_dtc_monitor_sip.yaml new file mode 100644 index 00000000..1fbc0e29 --- /dev/null +++ b/playbooks/delete_dtc_monitor_sip.yaml @@ -0,0 +1,17 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC SIP monitor Test + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + port: 8080 + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_snmp.yaml b/playbooks/delete_dtc_monitor_snmp.yaml new file mode 100644 index 00000000..972751a6 --- /dev/null +++ b/playbooks/delete_dtc_monitor_snmp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC SNMP monitor Test + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_monitor_tcp.yaml b/playbooks/delete_dtc_monitor_tcp.yaml new file mode 100644 index 00000000..662df448 --- /dev/null +++ b/playbooks/delete_dtc_monitor_tcp.yaml @@ -0,0 +1,16 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.36.118.2 + username: cloudadmin + password: admin + + connection: local + tasks: + - name: Delete Nios DTC TCP monitor Test + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_dtc_topology.yml b/playbooks/delete_dtc_topology.yml new file mode 100644 index 00000000..1782aa67 --- /dev/null +++ b/playbooks/delete_dtc_topology.yml @@ -0,0 +1,16 @@ +--- +- hosts: localhost + vars: + nios_provider: + host: 10.196.205.10 + username: cloudadmin + password: infoblox + wapi_version: "2.12" + + connection: local + tasks: + - name: delete a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" diff --git a/playbooks/delete_mx_record.yaml b/playbooks/delete_mx_record.yaml index 3b269a25..9a4475ec 100644 --- a/playbooks/delete_mx_record.yaml +++ b/playbooks/delete_mx_record.yaml @@ -9,7 +9,7 @@ connection: local tasks: - - name: Create Nios MX record + - name: delete Nios MX record infoblox.nios_modules.nios_mx_record: name: ansible.com mx: mailhost.ansible.com diff --git a/playbooks/delete_txt_record.yaml b/playbooks/delete_txt_record.yaml index 376e2973..ea9269af 100644 --- a/playbooks/delete_txt_record.yaml +++ b/playbooks/delete_txt_record.yaml @@ -9,7 +9,7 @@ connection: local tasks: - - name: Create Nios TXT record + - name: delete Nios TXT record infoblox.nios_modules.nios_txt_record: name: fqdn.txt.ansible.com text: example_text diff --git a/playbooks/restart_services.yml b/playbooks/restart_services.yml index 23bbe590..b8b8fe61 100644 --- a/playbooks/restart_services.yml +++ b/playbooks/restart_services.yml @@ -10,6 +10,6 @@ connection: local tasks: - name: Restart Services - nios_restartservices: + infoblox.nios_modules.nios_restartservices: provider: "{{ nios_provider }}" ... diff --git a/playbooks/update_member.yml b/playbooks/update_member.yml new file mode 100644 index 00000000..39156913 --- /dev/null +++ b/playbooks/update_member.yml @@ -0,0 +1,22 @@ +--- + +- hosts: localhost + vars: + nios_provider: + host: 10.34.10.724 + username: admin + password: cloudadmin + connection: local + tasks: + - name: update member host name + infoblox.nios_modules.nios_member: + host_name: {old_name: block1.localdomain, new_name: member01.localdomain} + master_candidate: false + vip_setting: + - address: 120.0.0.25 + subnet_mask: 255.255.255.0 + gateway: 120.0.0.1 + config_addr_type: IPV4 + platform: VNIOS + state: present + provider: "{{ nios_provider }}" \ No newline at end of file diff --git a/plugins/doc_fragments/nios.py b/plugins/doc_fragments/nios.py index 68c582f5..bbecf7a6 100644 --- a/plugins/doc_fragments/nios.py +++ b/plugins/doc_fragments/nios.py @@ -37,6 +37,20 @@ class ModuleDocFragment(object): - Value can also be specified using C(INFOBLOX_PASSWORD) environment variable. type: str + cert: + description: + - Specifies the client certificate file with digest of x509 config + for extra layer secure connection the remote instance of NIOS. + - Value can also be specified using C(INFOBLOX_CERT) environment + variable. + type: str + key: + description: + - Specifies private key file for encryption with the certificate + in order to connect with remote instance of NIOS. + - Value can also be specified using C(INFOBLOX_KEY) environment + variable. + type: str validate_certs: description: - Boolean value to enable or disable verifying SSL certificates @@ -63,11 +77,11 @@ class ModuleDocFragment(object): wapi_version: description: - Specifies the version of WAPI to use - - Value can also be specified using C(INFOBLOX_WAP_VERSION) environment + - Value can also be specified using C(INFOBLOX_WAPI_VERSION) environment variable. - Until ansible 2.8 the default WAPI was 1.4 type: str - default: '2.1' + default: '2.9' max_results: description: - Specifies the maximum number of objects to be returned, diff --git a/plugins/lookup/nios_next_ip.py b/plugins/lookup/nios_next_ip.py index f10203a5..e2fa076d 100644 --- a/plugins/lookup/nios_next_ip.py +++ b/plugins/lookup/nios_next_ip.py @@ -33,6 +33,11 @@ required: false type: list elements: str + network_view: + description: The network view to retrieve the CIDR network from. + required: false + default: default + type: str ''' EXAMPLES = """ @@ -40,6 +45,11 @@ ansible.builtin.set_fact: ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" +- name: return next available IP address for network 192.168.10.0/24 in a non-default network view + ansible.builtin.set_fact: + ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', network_view='ansible', \ + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + - name: return the next 3 available IP addresses for network 192.168.10.0/24 ansible.builtin.set_fact: ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, @@ -91,9 +101,14 @@ def run(self, terms, variables=None, **kwargs): num = kwargs.get('num', 1) exclude_ip = kwargs.get('exclude', []) + network_view = kwargs.get('network_view', 'default') try: - ref = network_obj[0]['_ref'] + ref_list = [network['_ref'] for network in network_obj if network['network_view'] == network_view] + if not ref_list: + raise AnsibleError('no records found') + else: + ref = ref_list[0] avail_ips = wapi.call_func('next_available_ip', ref, {'num': num, 'exclude': exclude_ip}) return [avail_ips['ips']] except Exception as exc: diff --git a/plugins/lookup/nios_next_network.py b/plugins/lookup/nios_next_network.py index 293dddb3..af3dbf65 100644 --- a/plugins/lookup/nios_next_network.py +++ b/plugins/lookup/nios_next_network.py @@ -41,6 +41,11 @@ default: '' type: list elements: str + network_view: + description: The network view to retrieve the CIDR network from. + required: false + default: default + type: str ''' EXAMPLES = """ @@ -49,6 +54,11 @@ networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" +- name: return next available network for network-container 192.168.10.0/24 in a non-default network view + ansible.builtin.set_fact: + networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, network_view='ansible' + provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}" + - name: return the next 2 available network addresses for network-container 192.168.10.0/24 ansible.builtin.set_fact: networkaddr: "{{ lookup('infoblox.nios_modules.nios_next_network', '192.168.10.0/24', cidr=25, num=2, @@ -94,9 +104,14 @@ def run(self, terms, variables=None, **kwargs): raise AnsibleError('unable to find network-container object %s' % network) num = kwargs.get('num', 1) exclude_ip = kwargs.get('exclude', []) + network_view = kwargs.get('network_view', 'default') try: - ref = network_obj[0]['_ref'] + ref_list = [network['_ref'] for network in network_obj if network['network_view'] == network_view] + if not ref_list: + raise AnsibleError('no records found') + else: + ref = ref_list[0] avail_nets = wapi.call_func('next_available_network', ref, {'cidr': cidr, 'num': num, 'exclude': exclude_ip}) return [avail_nets['networks']] except Exception as exc: diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index d2bfd0c9..a45928cc 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -29,13 +29,14 @@ # +import json import os from functools import partial from ansible.module_utils._text import to_native from ansible.module_utils.six import iteritems from ansible.module_utils._text import to_text from ansible.module_utils.basic import env_fallback -from ansible.module_utils.common.validation import check_type_dict +from ansible.module_utils.common.validation import check_type_dict, safe_eval try: from infoblox_client.connector import Connector @@ -49,6 +50,7 @@ NIOS_NETWORK_VIEW = 'networkview' NIOS_HOST_RECORD = 'record:host' NIOS_IPV4_NETWORK = 'network' +NIOS_RANGE = 'range' NIOS_IPV6_NETWORK = 'ipv6network' NIOS_ZONE = 'zone_auth' NIOS_PTR_RECORD = 'record:ptr' @@ -73,19 +75,28 @@ NIOS_NSGROUP_FORWARDINGMEMBER = 'nsgroup:forwardingmember' NIOS_NSGROUP_DELEGATION = 'nsgroup:delegation' NIOS_NSGROUP_STUBMEMBER = 'nsgroup:stubmember' +NIOS_DTC_MONITOR_HTTP = 'dtc:monitor:http' +NIOS_DTC_MONITOR_ICMP = 'dtc:monitor:icmp' +NIOS_DTC_MONITOR_PDP = 'dtc:monitor:pdp' +NIOS_DTC_MONITOR_SIP = 'dtc:monitor:sip' +NIOS_DTC_MONITOR_SNMP = 'dtc:monitor:snmp' +NIOS_DTC_MONITOR_TCP = 'dtc:monitor:tcp' +NIOS_DTC_TOPOLOGY = 'dtc:topology' NIOS_PROVIDER_SPEC = { 'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])), 'username': dict(fallback=(env_fallback, ['INFOBLOX_USERNAME'])), 'password': dict(fallback=(env_fallback, ['INFOBLOX_PASSWORD']), no_log=True), + 'cert': dict(fallback=(env_fallback, ['INFOBLOX_CERT'])), + 'key': dict(fallback=(env_fallback, ['INFOBLOX_KEY']), no_log=True), 'validate_certs': dict(type='bool', default=False, fallback=(env_fallback, ['INFOBLOX_SSL_VERIFY']), aliases=['ssl_verify']), 'silent_ssl_warnings': dict(type='bool', default=True), 'http_request_timeout': dict(type='int', default=10, fallback=(env_fallback, ['INFOBLOX_HTTP_REQUEST_TIMEOUT'])), 'http_pool_connections': dict(type='int', default=10), 'http_pool_maxsize': dict(type='int', default=10), 'max_retries': dict(type='int', default=3, fallback=(env_fallback, ['INFOBLOX_MAX_RETRIES'])), - 'wapi_version': dict(default='2.1', fallback=(env_fallback, ['INFOBLOX_WAP_VERSION'])), - 'max_results': dict(type='int', default=1000, fallback=(env_fallback, ['INFOBLOX_MAX_RETRIES'])) + 'wapi_version': dict(default='2.9', fallback=(env_fallback, ['INFOBLOX_WAPI_VERSION'])), + 'max_results': dict(type='int', default=1000, fallback=(env_fallback, ['INFOBLOX_MAX_RESULTS'])) } @@ -113,7 +124,12 @@ def get_connector(*args, **kwargs): # explicitly set env = ('INFOBLOX_%s' % key).upper() if env in os.environ: - kwargs[key] = os.environ.get(env) + if NIOS_PROVIDER_SPEC[key].get('type') == 'bool': + kwargs[key] = eval(os.environ.get(env).title()) + elif NIOS_PROVIDER_SPEC[key].get('type') == 'int': + kwargs[key] = eval(os.environ.get(env)) + else: + kwargs[key] = os.environ.get(env) if 'validate_certs' in kwargs.keys(): kwargs['ssl_verify'] = kwargs['validate_certs'] @@ -183,6 +199,25 @@ def member_normalize(member_spec): return member_spec +def convert_members_to_struct(member_spec): + ''' Transforms the members list of the Network module arguments into a + valid WAPI struct. This function will change arguments into the valid + wapi structure of the format: + { + network: 10.1.1.0/24 + members: + [ + {'_struct': 'dhcpmember', 'name': 'member_name1'}, + {'_struct': 'dhcpmember', 'name': 'member_name2'} + {'_struct': 'dhcpmember', 'name': '...'} + ] + } + ''' + if 'members' in member_spec.keys(): + member_spec['members'] = [{'_struct': 'dhcpmember', 'name': k['name']} for k in member_spec['members']] + return member_spec + + def normalize_ib_spec(ib_spec): result = {} for arg in ib_spec: @@ -232,6 +267,11 @@ class WapiInventory(WapiBase): pass +class AnsibleError(Exception): + '''Implements raising exceptions''' + pass + + class WapiModule(WapiBase): ''' Implements WapiBase for executing a NIOS module ''' def __init__(self, module): @@ -277,6 +317,17 @@ def run(self, ib_obj_type, ib_spec): # get object reference ib_obj_ref, update, new_name = self.get_object_ref(self.module, ib_obj_type, obj_filter, ib_spec) + + # When a range update is defined, check for a range that matches the target range definition as well + # to allows for idempotence + if ib_obj_type == NIOS_RANGE and len(ib_obj_ref) == 0 and \ + (True for v in ('new_start_addr', 'new_end_addr') if v in ib_spec.keys()): + if self.module.params.get('new_start_addr'): + obj_filter['start_addr'] = self.module.params.get('new_start_addr') + if self.module.params.get('new_end_addr'): + obj_filter['end_addr'] = self.module.params.get('new_end_addr') + ib_obj_ref, update, new_name = self.get_object_ref(self.module, ib_obj_type, obj_filter, ib_spec) + proposed_object = {} for key, value in iteritems(ib_spec): if self.module.params[key] is not None: @@ -296,8 +347,9 @@ def run(self, ib_obj_type, ib_spec): # To check for existing A_record with same name with input A_record by IP if each.get('ipv4addr') and each.get('ipv4addr') == proposed_object.get('ipv4addr'): current_object = each + break # To check for existing Host_record with same name with input Host_record by IP - elif each.get('ipv4addrs')[0].get('ipv4addr') and each.get('ipv4addrs')[0].get('ipv4addr')\ + elif each.get('ipv4addrs') and each.get('ipv4addrs')[0].get('ipv4addr')\ == proposed_object.get('ipv4addrs')[0].get('ipv4addr'): current_object = each # Else set the current_object with input value @@ -316,10 +368,43 @@ def run(self, ib_obj_type, ib_spec): # checks if the object type is member to normalize the attributes being passed if (ib_obj_type == NIOS_MEMBER): proposed_object = member_normalize(proposed_object) + # The WAPI API will never return the "create_token" field that causes a difference + # with the defaults of the module. To prevent this we remove the "create_token" option + # if it has not been set to true. + if (proposed_object.get("create_token") is not True): + proposed_object.pop("create_token") + + if (ib_obj_type == NIOS_IPV4_NETWORK or ib_obj_type == NIOS_IPV6_NETWORK): + proposed_object = convert_members_to_struct(proposed_object) + + if (ib_obj_type == NIOS_RANGE): + if proposed_object.get('new_start_addr'): + proposed_object['start_addr'] = proposed_object.get('new_start_addr') + del proposed_object['new_start_addr'] + if proposed_object.get('new_end_addr'): + proposed_object['end_addr'] = proposed_object.get('new_end_addr') + del proposed_object['new_end_addr'] + + # checks if the 'text' field has to be updated for the TXT Record + if (ib_obj_type == NIOS_TXT_RECORD): + text_obj = proposed_object["text"] + if text_obj.startswith("{"): + try: + text_obj = json.loads(text_obj) + txt = text_obj['new_text'] + except Exception: + (result, exc) = safe_eval(text_obj, dict(), include_exceptions=True) + if exc is not None: + raise TypeError('unable to evaluate string as dictionary') + txt = result['new_text'] + proposed_object['text'] = txt # checks if the name's field has been updated if update and new_name: - proposed_object['name'] = new_name + if (ib_obj_type == NIOS_MEMBER): + proposed_object['host_name'] = new_name + else: + proposed_object['name'] = new_name check_remove = [] if (ib_obj_type == NIOS_HOST_RECORD): @@ -336,6 +421,9 @@ def run(self, ib_obj_type, ib_spec): if 'remove' in proposed_object['ipv4addrs'][0]: del proposed_object['ipv4addrs'][0]['remove'] + # Checks if 'new_ipv4addr' param exists in ipv4addr args + proposed_object = self.check_for_new_ipv4addr(proposed_object) + res = None modified = not self.compare_objects(current_object, proposed_object) if 'extattrs' in proposed_object: @@ -350,7 +438,7 @@ def run(self, ib_obj_type, ib_spec): self.create_object(ib_obj_type, proposed_object) result['changed'] = True # Check if NIOS_MEMBER and the flag to call function create_token is set - elif (ib_obj_type == NIOS_MEMBER) and (proposed_object['create_token']): + elif (ib_obj_type == NIOS_MEMBER) and (proposed_object.get("create_token") is True): proposed_object = None # the function creates a token that can be used by a pre-provisioned member to join the grid result['api_results'] = self.call_func('create_token', ref, proposed_object) @@ -385,7 +473,7 @@ def run(self, ib_obj_type, ib_spec): del proposed_object['zone_format'] self.update_object(ref, proposed_object) result['changed'] = True - elif 'network_view' in proposed_object and (ib_obj_type not in (NIOS_IPV4_FIXED_ADDRESS, NIOS_IPV6_FIXED_ADDRESS)): + elif 'network_view' in proposed_object and (ib_obj_type not in (NIOS_IPV4_FIXED_ADDRESS, NIOS_IPV6_FIXED_ADDRESS, NIOS_RANGE)): proposed_object.pop('network_view') result['changed'] = True if not self.module.check_mode and res is None: @@ -423,6 +511,17 @@ def check_if_recordname_exists(self, obj_filter, ib_obj_ref, ib_obj_type, curren if obj_host_name == ref_host_name and current_ip_addr != proposed_ip_addr: self.create_object(ib_obj_type, proposed_object) + def get_network_view(self, proposed_object): + ''' Check for the associated network view with + the given dns_view''' + try: + network_view_ref = self.get_object('view', {"name": proposed_object['view']}, return_fields=['network_view']) + if network_view_ref: + network_view = network_view_ref[0].get('network_view') + except Exception: + raise Exception("object with dns_view: %s not found" % (proposed_object['view'])) + return network_view + def check_if_nios_next_ip_exists(self, proposed_object): ''' Check if nios_next_ip argument is passed in ipaddr while creating host record, if yes then format proposed object ipv4addrs and pass @@ -436,7 +535,18 @@ def check_if_nios_next_ip_exists(self, proposed_object): elif 'ipv4addr' in proposed_object: if 'nios_next_ip' in proposed_object['ipv4addr']: ip_range = check_type_dict(proposed_object['ipv4addr'])['nios_next_ip'] - proposed_object['ipv4addr'] = NIOS_NEXT_AVAILABLE_IP + ':' + ip_range + net_view = self.get_network_view(proposed_object) + proposed_object['ipv4addr'] = NIOS_NEXT_AVAILABLE_IP + ':' + ip_range + ',' + net_view + + return proposed_object + + def check_for_new_ipv4addr(self, proposed_object): + ''' Checks if new_ipv4addr parameter is passed in the argument + while updating the record with new ipv4addr with static allocation''' + if 'ipv4addr' in proposed_object: + if 'new_ipv4addr' in proposed_object['ipv4addr']: + new_ipv4 = check_type_dict(proposed_object['ipv4addr'])['new_ipv4addr'] + proposed_object['ipv4addr'] = new_ipv4 return proposed_object @@ -468,6 +578,14 @@ def check_if_add_remove_ip_arg_exists(self, proposed_object): del proposed_object['ipv4addrs'][0]['remove'] return update, proposed_object + def check_next_ip_status(self, obj_filter): + ''' Checks if nios next ip argument exists if True returns true + else returns false''' + if 'ipv4addr' in obj_filter: + if 'nios_next_ip' in obj_filter['ipv4addr']: + return True + return False + def issubset(self, item, objects): ''' Checks if item is a subset of objects :args item: the subset item to validate @@ -483,6 +601,19 @@ def issubset(self, item, objects): if item in obj: return True + def compare_extattrs(self, current_extattrs, proposed_extattrs): + '''Compare current extensible attributes to given extensible + attribute, if length is not equal returns false , else + checks the value of keys in proposed extattrs''' + if len(current_extattrs) != len(proposed_extattrs): + return False + else: + for key, proposed_item in iteritems(proposed_extattrs): + current_item = current_extattrs.get(key) + if current_item != proposed_item: + return False + return True + def compare_objects(self, current_object, proposed_object): for key, proposed_item in iteritems(proposed_object): current_item = current_object.get(key) @@ -496,12 +627,32 @@ def compare_objects(self, current_object, proposed_object): if key == 'aliases': if set(current_item) != set(proposed_item): return False + # If the lists are of a different length the objects can not be + # equal and False will be returned before comparing the lists items + # this code part will work for members assignment + if key == 'members' and (len(proposed_item) != len(current_item)): + return False + for subitem in proposed_item: if not self.issubset(subitem, current_item): return False elif isinstance(proposed_item, dict): - return self.compare_objects(current_item, proposed_item) + # Compare the items of the dict to see if they are equal. A + # difference stops the comparison and returns false. If they + # are equal move on to the next item + + # Checks if extattrs existing in proposed object + if key == 'extattrs': + current_extattrs = current_object.get(key) + proposed_extattrs = proposed_object.get(key) + if not self.compare_extattrs(current_extattrs, proposed_extattrs): + return False + + if self.compare_objects(current_item, proposed_item) is False: + return False + else: + continue else: if current_item != proposed_item: @@ -514,30 +665,53 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): update = False old_name = new_name = None + old_ipv4addr_exists = old_text_exists = False + next_ip_exists = False if ('name' in obj_filter): # gets and returns the current object based on name/old_name passed try: name_obj = check_type_dict(obj_filter['name']) - old_name = name_obj['old_name'] - new_name = name_obj['new_name'] + # check if network_view allows searching and updating with camelCase + if (ib_obj_type == NIOS_NETWORK_VIEW): + old_name = name_obj['old_name'] + new_name = name_obj['new_name'] + else: + old_name = name_obj['old_name'].lower() + new_name = name_obj['new_name'].lower() except TypeError: name = obj_filter['name'] if old_name and new_name: if (ib_obj_type == NIOS_HOST_RECORD): test_obj_filter = dict([('name', old_name), ('view', obj_filter['view'])]) + # if there are multiple records with same name and different ip + elif (ib_obj_type == NIOS_A_RECORD): + test_obj_filter = dict([('name', old_name), ('ipv4addr', obj_filter['ipv4addr'])]) + try: + ipaddr_obj = check_type_dict(obj_filter['ipv4addr']) + ipaddr = ipaddr_obj.get('old_ipv4addr') + old_ipv4addr_exists = True if ipaddr else False + except TypeError: + ipaddr = test_obj_filter['ipv4addr'] + if old_ipv4addr_exists: + test_obj_filter['ipv4addr'] = ipaddr + else: + del test_obj_filter['ipv4addr'] else: test_obj_filter = dict([('name', old_name)]) # get the object reference ib_obj = self.get_object(ib_obj_type, test_obj_filter, return_fields=list(ib_spec.keys())) if ib_obj: obj_filter['name'] = new_name + elif old_ipv4addr_exists and (len(ib_obj) == 0): + raise Exception("object with name: '%s', ipv4addr: '%s' is not found" % (old_name, test_obj_filter['ipv4addr'])) else: - test_obj_filter['name'] = new_name - ib_obj = self.get_object(ib_obj_type, test_obj_filter, return_fields=list(ib_spec.keys())) + raise Exception("object with name: '%s' is not found" % (old_name)) update = True return ib_obj, update, new_name if (ib_obj_type == NIOS_HOST_RECORD): + # to fix the sanity issue + name = obj_filter['name'] # to check only by name if dns bypassing is set if not obj_filter['configure_for_dns']: test_obj_filter = dict([('name', name)]) @@ -557,42 +731,92 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): try: ipaddr_obj = check_type_dict(obj_filter['ipv4addr']) ipaddr = ipaddr_obj.get('old_ipv4addr') + old_ipv4addr_exists = True if ipaddr else False + if not old_ipv4addr_exists: + next_ip_exists = self.check_next_ip_status(test_obj_filter) except TypeError: ipaddr = obj_filter['ipv4addr'] - test_obj_filter['ipv4addr'] = ipaddr + if old_ipv4addr_exists: + test_obj_filter['ipv4addr'] = ipaddr + # resolve issue if nios_next_ip exists which is not searchable attribute + if next_ip_exists: + del test_obj_filter['ipv4addr'] elif (ib_obj_type == NIOS_TXT_RECORD): # resolves issue where multiple txt_records with same name and different text test_obj_filter = obj_filter try: - text_obj = check_type_dict(obj_filter['text']) - txt = text_obj['old_text'] + text_obj = obj_filter['text'] + if text_obj.startswith("{"): + try: + text_obj = json.loads(text_obj) + txt = text_obj['old_text'] + old_text_exists = True + except Exception: + (result, exc) = safe_eval(text_obj, dict(), include_exceptions=True) + if exc is not None: + raise TypeError('unable to evaluate string as dictionary') + txt = result['old_text'] + old_text_exists = True + else: + txt = text_obj except TypeError: txt = obj_filter['text'] test_obj_filter['text'] = txt + + # removing Port param from get params for NIOS_DTC_MONITOR_TCP + elif (ib_obj_type == NIOS_DTC_MONITOR_TCP): + test_obj_filter = dict([('name', obj_filter['name'])]) + # check if test_obj_filter is empty copy passed obj_filter else: test_obj_filter = obj_filter ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys())) + + # prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found + if old_ipv4addr_exists and (ib_obj is None or len(ib_obj) == 0): + raise Exception("A Record with ipv4addr: '%s' is not found" % (ipaddr)) + # prevents creation of a new TXT record with 'new_text' when TXT record with a particular 'old_text' is not found + if old_text_exists and ib_obj is None: + raise Exception("TXT Record with text: '%s' is not found" % (txt)) elif (ib_obj_type == NIOS_A_RECORD): # resolves issue where multiple a_records with same name and different IP address test_obj_filter = obj_filter try: ipaddr_obj = check_type_dict(obj_filter['ipv4addr']) ipaddr = ipaddr_obj.get('old_ipv4addr') + old_ipv4addr_exists = True if ipaddr else False except TypeError: ipaddr = obj_filter['ipv4addr'] test_obj_filter['ipv4addr'] = ipaddr ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys())) + # prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found + if old_ipv4addr_exists and ib_obj is None: + raise Exception("A Record with ipv4addr: '%s' is not found" % (ipaddr)) elif (ib_obj_type == NIOS_TXT_RECORD): # resolves issue where multiple txt_records with same name and different text test_obj_filter = obj_filter try: - text_obj = check_type_dict(obj_filter['text']) - txt = text_obj['old_text'] + text_obj = obj_filter(['text']) + if text_obj.startswith("{"): + try: + text_obj = json.loads(text_obj) + txt = text_obj['old_text'] + old_text_exists = True + except Exception: + (result, exc) = safe_eval(text_obj, dict(), include_exceptions=True) + if exc is not None: + raise TypeError('unable to evaluate string as dictionary') + txt = result['old_text'] + old_text_exists = True + else: + txt = text_obj except TypeError: txt = obj_filter['text'] test_obj_filter['text'] = txt ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys())) + # prevents creation of a new TXT record with 'new_text' when TXT record with a particular 'old_text' is not found + if old_text_exists and ib_obj is None: + raise Exception("TXT Record with text: '%s' is not found" % (txt)) elif (ib_obj_type == NIOS_ZONE): # del key 'restart_if_needed' as nios_zone get_object fails with the key present temp = ib_spec['restart_if_needed'] @@ -602,13 +826,70 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): if not ib_obj: ib_spec['restart_if_needed'] = temp elif (ib_obj_type == NIOS_MEMBER): - # del key 'create_token' as nios_member get_object fails with the key present - temp = ib_spec['create_token'] - del ib_spec['create_token'] + # gets and returns current_object as per old_name/host_name passed + test_obj_filter = obj_filter + try: + name_obj = check_type_dict(test_obj_filter['host_name']) + old_name = name_obj['old_name'] + new_name = name_obj['new_name'] + except TypeError: + host_name = obj_filter['host_name'] + + if old_name and new_name: + test_obj_filter['host_name'] = old_name + temp = ib_spec['create_token'] + del ib_spec['create_token'] + ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys())) + if temp: + # reinstate 'create_token' key + ib_spec['create_token'] = temp + if ib_obj: + obj_filter['host_name'] = new_name + else: + raise Exception("object with name: '%s' is not found" % (old_name)) + update = True + else: + # del key 'create_token' as nios_member get_object fails with the key present + temp = ib_spec['create_token'] + del ib_spec['create_token'] + ib_obj = self.get_object(ib_obj_type, obj_filter.copy(), return_fields=list(ib_spec.keys())) + if temp: + # reinstate 'create_token' key + ib_spec['create_token'] = temp + elif (ib_obj_type in (NIOS_IPV4_NETWORK, NIOS_IPV6_NETWORK, NIOS_IPV4_NETWORK_CONTAINER, NIOS_IPV6_NETWORK_CONTAINER)): + # del key 'template' as nios_network get_object fails with the key present + temp = ib_spec['template'] + del ib_spec['template'] + + if (ib_obj_type in (NIOS_IPV4_NETWORK_CONTAINER, NIOS_IPV6_NETWORK_CONTAINER)): + # del key 'members' as nios_network get_object fails with the key present + # Don't reinstate the field after as it is not valid for network containers + del ib_spec['members'] + ib_obj = self.get_object(ib_obj_type, obj_filter.copy(), return_fields=list(ib_spec.keys())) + # reinstate the 'template' and 'members' key if temp: - # reinstate 'create_token' key - ib_spec['create_token'] = temp + ib_spec['template'] = temp + + elif (ib_obj_type in (NIOS_RANGE)): + # Delete the update keys to find the original range object + new_start = ib_spec.get('new_start_addr') + new_end = ib_spec.get('new_end_addr') + del ib_spec['new_start_addr'] + del ib_spec['new_end_addr'] + new_start_arg = self.module.params.get('new_start_addr') + new_end_arg = self.module.params.get('new_end_addr') + ib_obj = self.get_object(ib_obj_type, obj_filter.copy(), return_fields=list(ib_spec.keys())) + # Restore the keys to the object. + if new_start: + ib_spec['new_start_addr'] = new_start + if new_end: + ib_spec['new_end_addr'] = new_end + + # throws exception if start_addr and end_addr doesn't exists for updating range + if (new_start_arg and new_end_arg): + if not ib_obj: + raise Exception('Specified range %s-%s not found' % (obj_filter['start_addr'], obj_filter['end_addr'])) else: ib_obj = self.get_object(ib_obj_type, obj_filter.copy(), return_fields=list(ib_spec.keys())) return ib_obj, update, new_name diff --git a/plugins/modules/nios_a_record.py b/plugins/modules/nios_a_record.py index 0164e94e..7e50ef09 100644 --- a/plugins/modules/nios_a_record.py +++ b/plugins/modules/nios_a_record.py @@ -25,7 +25,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. Users can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples. required: true type: str view: @@ -40,7 +41,9 @@ description: - Configures the IPv4 address for this A record. Users can dynamically allocate ipv4 address to A record by passing dictionary containing, - I(nios_next_ip) and I(CIDR network range). See example. + I(nios_next_ip) and I(CIDR network range). Also update ipv4 address + statically to A record by passing dictionary containing, I(old_ipv4addr) + and I(new_ipv4addr). See example. aliases: - ipv4 required: true @@ -109,6 +112,32 @@ password: admin connection: local +- name: Update an A record in custom view with a dynamic IP using nios_next_ip + infoblox.nios_modules.nios_a_record: + name: test.parent.com + view: default.custom + ipv4: {'old_ipv4addr': '10.0.0.5', nios_next_ip: 80.0.0.0/24} + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Update an A record with static ip + infoblox.nios_modules.nios_a_record: + name: test.parent.com + view: default.custom + ipv4: {'old_ipv4addr': '10.0.0.5', new_ipv4addr: '17.0.0.5'} + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Update an A record name infoblox.nios_modules.nios_a_record: name: {new_name: a_new.ansible.com, old_name: a.ansible.com} @@ -135,7 +164,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_A_RECORD from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_aaaa_record.py b/plugins/modules/nios_aaaa_record.py index bbafe8db..cb48ee65 100644 --- a/plugins/modules/nios_aaaa_record.py +++ b/plugins/modules/nios_aaaa_record.py @@ -22,7 +22,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. User can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples required: true type: str view: @@ -123,7 +124,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_AAAA_RECORD from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_cname_record.py b/plugins/modules/nios_cname_record.py index 5bc117d1..b03b48e9 100644 --- a/plugins/modules/nios_cname_record.py +++ b/plugins/modules/nios_cname_record.py @@ -25,7 +25,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. User can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples required: true type: str view: @@ -96,6 +97,17 @@ password: admin connection: local +- name: Update name of CNAME record + infoblox.nios_modules.nios_cname_record: + name: {old_name: cname.ansibletestzone.com, new_name: demo.ansibletestzone.com} + canonical: realhost.ansible.com + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Remove a CNAME record from the system infoblox.nios_modules.nios_cname_record: name: cname.ansible.com @@ -111,7 +123,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_CNAME_RECORD from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_dtc_lbdn.py b/plugins/modules/nios_dtc_lbdn.py index 392a7cb5..bc5a79c1 100644 --- a/plugins/modules/nios_dtc_lbdn.py +++ b/plugins/modules/nios_dtc_lbdn.py @@ -37,6 +37,12 @@ - RATIO - ROUND_ROBIN - TOPOLOGY + topology: + description: + - Configures the topology rules for the C(TOPOLOGY) load balancing method. + - Required only when I(lb_method) is set to C(TOPOLOGY). + required: false + type: str auth_zones: description: - List of linked authoritative zones. @@ -159,7 +165,6 @@ from ..module_utils.api import NIOS_DTC_LBDN from ..module_utils.api import WapiModule from ..module_utils.api import normalize_ib_spec -from ansible.module_utils.six import iteritems from ansible.module_utils.basic import AnsibleModule @@ -173,7 +178,7 @@ def auth_zones_transform(module): for zone in module.params['auth_zones']: zone_obj = wapi.get_object('zone_auth', {'fqdn': zone}) - if zone_obj is not None: + if zone_obj: zone_list.append(zone_obj[0]['_ref']) else: module.fail_json( @@ -189,13 +194,23 @@ def pools_transform(module): {'name': pool['pool']}) if 'ratio' not in pool: pool['ratio'] = 1 - if pool_obj is not None: + if pool_obj: pool_list.append({'pool': pool_obj[0]['_ref'], 'ratio': pool['ratio']}) else: module.fail_json(msg='pool %s cannot be found.' % pool) return pool_list + def topology_transform(module): + topology = module.params['topology'] + if topology: + topo_obj = wapi.get_object('dtc:topology', {'name': topology}) + if topo_obj: + return topo_obj[0]['_ref'] + else: + module.fail_json( + msg='topology %s cannot be found.' % topology) + auth_zones_spec = dict() pools_spec = dict( @@ -208,6 +223,7 @@ def pools_transform(module): lb_method=dict(required=True, choices=['GLOBAL_AVAILABILITY', 'RATIO', 'ROUND_ROBIN', 'TOPOLOGY']), + topology=dict(type='str', transform=topology_transform), auth_zones=dict(type='list', elements='str', options=auth_zones_spec, transform=auth_zones_transform), patterns=dict(type='list', elements='str'), diff --git a/plugins/modules/nios_dtc_monitor_http.py b/plugins/modules/nios_dtc_monitor_http.py new file mode 100644 index 00000000..b90e98a0 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_http.py @@ -0,0 +1,272 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_http +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC HTTP monitors +description: + - Adds and/or removes instances of DTC HTTP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:http) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for HTTP requests. + type: int + default: 80 + ciphers: + description: + - Configures an optional cipher list for the secure HTTP/S connection. + type: str + client_cert: + description: + - Configures an optional client certificate, supplied in a secure HTTP/S + mode if present. + type: str + content_check: + description: + - Configures the content check type + type: str + choices: + - EXTRACT + - MATCH + - NONE + default: NONE + content_check_input: + description: + - Configures the portion of the response to use as input for content check. + type: str + choices: + - ALL + - BODY + - HEADERS + default: ALL + content_check_op: + description: + - Configures the content check success criteria operator. + type: str + choices: + - EQ + - GEQ + - LEQ + - NEQ + content_check_regex: + description: + - Configures the content check regular expression. Values with leading + or trailing white space are not valid for this field. + type: str + content_extract_group: + description: + - Configures the content extraction sub-expression to extract. + type: int + default: 0 + content_extract_type: + description: + - Configures the content extraction expected type for the extracted data. + type: str + choices: + - INTEGER + - STRING + default: STRING + content_extract_value: + description: + - Configures the content extraction value to compare with the extracted + result. Values with leading or trailing white space are not valid for + this field. + type: str + request: + description: + - Configures the HTTP request to send + type: str + default: GET / + result: + description: + - Configures the type of the expected result + type: str + choices: + - ANY + - CODE_IS + - CODE_IS_NOT + default: ANY + result_code: + description: + - Configures the expected return code + type: int + default: 200 + enable_sni: + description: + - Configures whether or not Server Name Indication (SNI) for the HTTPS + monitor is enabled. + type: bool + default: false + secure: + description: + - Configures the security status of the connection. + type: bool + default: false + validate_cert: + description: + - Configures whether the validation of the remote server's certificate is + enabled. + type: bool + default: true + interval: + description: + - Configures the interval for HTTP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for HTTP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_HTTP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=80), + ciphers=dict(type='str'), + client_cert=dict(type='str'), + content_check=dict(default='NONE', choices=['EXTRACT', 'MATCH', 'NONE']), + content_check_input=dict(default='ALL', choices=['ALL', 'BODY', 'HEADERS']), + content_check_op=dict(choices=['EQ', 'GEQ', 'LEQ', 'NEQ']), + content_check_regex=dict(type='str'), + content_extract_group=dict(type='int', default=0), + content_extract_type=dict(default='STRING', choices=['INTEGER', 'STRING']), + content_extract_value=dict(type='str'), + request=dict(type='str', default='GET /'), + result=dict(default='ANY', choices=['ANY', 'CODE_IS', 'CODE_IS_NOT']), + result_code=dict(type='int', default=200), + enable_sni=dict(type='bool', default=False), + secure=dict(type='bool', default=False), + validate_cert=dict(type='bool', default=True), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_HTTP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_icmp.py b/plugins/modules/nios_dtc_monitor_icmp.py new file mode 100644 index 00000000..e133954e --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_icmp.py @@ -0,0 +1,154 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_icmp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC ICMP monitors +description: + - Adds and/or removes instances of DTC ICMP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:icmp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + interval: + description: + - Configures the interval for ICMP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for ICMP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_ICMP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_ICMP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_pdp.py b/plugins/modules/nios_dtc_monitor_pdp.py new file mode 100644 index 00000000..d9cf8e4a --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_pdp.py @@ -0,0 +1,159 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_pdp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC PDP monitors +description: + - Adds and/or removes instances of DTC PDP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:pdp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for PDP requests. + type: int + default: 2123 + interval: + description: + - Configures the interval for PDP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for PDP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_PDP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=2123), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_PDP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_sip.py b/plugins/modules/nios_dtc_monitor_sip.py new file mode 100644 index 00000000..c1df0985 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_sip.py @@ -0,0 +1,209 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_sip +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC SIP monitors +description: + - Adds and/or removes instances of DTC SIP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:sip) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for SIP requests. + type: int + default: 5060 + ciphers: + description: + - Configures an optional cipher list for the secure TLS/SIPS connection. + type: str + client_cert: + description: + - Configures an optional client certificate, supplied in TLS or SIPS mode + if present. + type: str + request: + description: + - Configures the SIP request to send + type: str + result: + description: + - Configures the type of the expected result + type: str + choices: + - ANY + - CODE_IS + - CODE_IS_NOT + default: ANY + result_code: + description: + - Configures the expected return code + type: int + default: 200 + transport: + description: + - Configures the transport layer protocol to use for the SIP check + type: str + choices: + - SIPS + - TCP + - TLS + - UDP + default: TCP + validate_cert: + description: + - Configures whether the validation of the remote server's certificate is + enabled. + type: bool + default: true + interval: + description: + - Configures the interval for SIP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for SIP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_SIP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=5060), + ciphers=dict(type='str'), + client_cert=dict(type='str'), + request=dict(type='str'), + result=dict(default='ANY', choices=['ANY', 'CODE_IS', 'CODE_IS_NOT']), + result_code=dict(type='int', default=200), + transport=dict(default='TCP', choices=['SIPS', 'TCP', 'TLS', 'UDP']), + validate_cert=dict(type='bool', default=True), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_SIP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_snmp.py b/plugins/modules/nios_dtc_monitor_snmp.py new file mode 100644 index 00000000..036580e8 --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_snmp.py @@ -0,0 +1,279 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_snmp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC SNMP monitors +description: + - Adds and/or removes instances of DTC SNMP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:snmp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for SNMP requests. + type: int + default: 161 + version: + description: + - Configures the SNMP protocol version for the SNMP health check. + type: str + choices: + - V1 + - V2C + - V3 + default: V2C + community: + description: + - Configures the SNMP community string for SNMP authentication. + type: str + default: public + user: + description: + - Configures the SNMPv3 user setting. + type: str + context: + description: + - Configures the SNMPv3 context. Values with leading or trailing white + space are not valid for this field. + type: str + engine_id: + description: + - Configures the SNMPv3 engine identifier. Values with leading or + trailing white space are not valid for this field. + type: str + oids: + description: + - Configures the list of OIDs for SNMP monitoring. + type: list + elements: dict + suboptions: + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + condition: + description: + - Configures the condition of the validation result for the SNMP + health check. + type: str + choices: + - ANY + - EXACT + - GEQ + - LEQ + - RANGE + default: ANY + first: + description: + - Configures the condition's first term to match against the SNMP + health check result. + type: str + last: + description: + - Configures the condition's second term to match against the SNMP + health check result with 'RANGE' condition. + type: str + oid: + description: + - Configures the SNMP OID value for DTC SNMP Monitor health checks. + - This field is required on creation + required: true + type: str + type: + description: + - Configures the condition type for DTC SNMP Monitor health checks + results. + type: str + choices: + - INTEGER + - STRING + default: STRING + interval: + description: + - Configures the interval for SNMP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for SNMP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_SNMP +from ..module_utils.api import normalize_ib_spec + + +def oids(module): + ''' Transform the module argument into a valid WAPI struct + This function will transform the oids argument into a structure that is a + valid WAPI structure in the format of: + { + comment: , + condition: , + first: , + last: , + oid: , + type: , + } + It will remove any options that are set to None since WAPI will error on + that condition. + The remainder of the value validation is performed by WAPI + ''' + + oids = list() + for item in module.params['oids']: + oid = dict([(k, v) for k, v in iteritems(item) if v is not None]) + if 'oid' not in oid: + module.fail_json(msg='oid is required for oid value') + oids.append(oid) + return oids + + +def main(): + ''' Main entry point for module execution + ''' + + oid_spec = dict( + comment=dict(type='str'), + condition=dict(default='ANY', choices=['ANY', 'EXACT', 'GEQ', 'LEQ', 'RANGE']), + first=dict(type='str'), + last=dict(type='str'), + oid=dict(type='str', required=True), + type=dict(default='STRING', choices=['INTEGER', 'STRING']) + ) + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + port=dict(type='int', default=161), + version=dict(default='V2C', choices=['V1', 'V2C', 'V3']), + community=dict(type='str', default='public'), + user=dict(type='str'), + context=dict(type='str'), + engine_id=dict(type='str'), + oids=dict(type='list', elements='dict', options=oid_spec, transform=oids), + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_SNMP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_monitor_tcp.py b/plugins/modules/nios_dtc_monitor_tcp.py new file mode 100644 index 00000000..e812f13c --- /dev/null +++ b/plugins/modules/nios_dtc_monitor_tcp.py @@ -0,0 +1,163 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_monitor_tcp +author: "Joachim Buyse (@jbisabel)" +version_added: "1.6.0" +short_description: Configure Infoblox NIOS DTC TCP monitors +description: + - Adds and/or removes instances of DTC TCP monitor objects from Infoblox NIOS + servers. This module manages C(dtc:monitor:tcp) objects using the Infoblox + WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Configures the display name for this DTC monitor. Values with leading + or trailing white space are not valid for this field. + required: true + type: str + port: + description: + - Configures the port value for TCP requests. The field is required on + creation. + required: true + type: int + interval: + description: + - Configures the interval for TCP health check. + type: int + default: 5 + retry_down: + description: + - Configures the value of how many times the server should appear as + down to be treated as dead after it was alive. + type: int + default: 1 + retry_up: + description: + - Configures the value of how many times the server should appear as up + to be treated as alive after it was dead. + type: int + default: 1 + timeout: + description: + - Configures the timeout for TCP health check in seconds. + type: int + default: 15 + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_MONITOR_TCP +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + ib_spec = dict( + name=dict(required=True, ib_req=True), + port=dict(type='int', required=True, ib_req=True), + + interval=dict(type='int', default=5), + retry_down=dict(type='int', default=1), + retry_up=dict(type='int', default=1), + timeout=dict(type='int', default=15), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_MONITOR_TCP, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_dtc_pool.py b/plugins/modules/nios_dtc_pool.py index 2611fe1b..82491f62 100644 --- a/plugins/modules/nios_dtc_pool.py +++ b/plugins/modules/nios_dtc_pool.py @@ -41,6 +41,12 @@ - TOPOLOGY required: true type: str + lb_preferred_topology: + description: + - Configures the topology rules for the C(TOPOLOGY) load balancing method. + - Required only when I(lb_preferred_method) is set to C(TOPOLOGY). + required: false + type: str servers: description: - Configure the DTC Servers related to the pool @@ -157,7 +163,6 @@ from ..module_utils.api import NIOS_DTC_POOL from ..module_utils.api import WapiModule from ..module_utils.api import normalize_ib_spec -from ansible.module_utils.six import iteritems from ansible.module_utils.basic import AnsibleModule @@ -171,9 +176,11 @@ def servers_transform(module): for server in module.params['servers']: server_obj = wapi.get_object('dtc:server', {'name': server['server']}) - if server_obj is not None: + if server_obj: server_list.append({'server': server_obj[0]['_ref'], 'ratio': server['ratio']}) + else: + module.fail_json(msg='Server %s cannot be found.' % server) return server_list def monitors_transform(module): @@ -182,10 +189,23 @@ def monitors_transform(module): for monitor in module.params['monitors']: monitor_obj = wapi.get_object('dtc:monitor:' + monitor['type'], {'name': monitor['name']}) - if monitor_obj is not None: + if monitor_obj: monitor_list.append(monitor_obj[0]['_ref']) + else: + module.fail_json( + msg='monitor %s cannot be found.' % monitor) return monitor_list + def topology_transform(module): + topology = module.params['lb_preferred_topology'] + if topology: + topo_obj = wapi.get_object('dtc:topology', {'name': topology}) + if topo_obj: + return topo_obj[0]['_ref'] + else: + module.fail_json( + msg='topology %s cannot be found.' % topology) + servers_spec = dict( server=dict(required=True), ratio=dict(type='int', default=1) @@ -204,6 +224,7 @@ def monitors_transform(module): 'RATIO', 'ROUND_ROBIN', 'TOPOLOGY']), + lb_preferred_topology=dict(type='str', transform=topology_transform), servers=dict(type='list', elements='dict', options=servers_spec, transform=servers_transform), diff --git a/plugins/modules/nios_dtc_server.py b/plugins/modules/nios_dtc_server.py index 2b613577..1da6a5eb 100644 --- a/plugins/modules/nios_dtc_server.py +++ b/plugins/modules/nios_dtc_server.py @@ -33,6 +33,13 @@ of the server required: true type: str + disable: + description: + - Determines whether the DTC Server is disabled or not. + When this is set to False, the fixed address is enabled. + required: false + type: bool + default: False extattrs: description: - Allows for the configuration of Extensible Attributes on the @@ -97,7 +104,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_DTC_SERVER from ..module_utils.api import normalize_ib_spec @@ -111,6 +117,7 @@ def main(): name=dict(required=True, ib_req=True), host=dict(required=True, ib_req=True), + disable=dict(type='bool', default=False), extattrs=dict(type='dict'), comment=dict(), ) diff --git a/plugins/modules/nios_dtc_topology.py b/plugins/modules/nios_dtc_topology.py new file mode 100644 index 00000000..eec85725 --- /dev/null +++ b/plugins/modules/nios_dtc_topology.py @@ -0,0 +1,253 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_dtc_topology +author: "Joachim Buyse (@jbisabel)" +short_description: Configure Infoblox NIOS DTC Topology +version_added: "1.6.0" +description: + - Adds and/or removes instances of DTC Topology objects from + Infoblox NIOS topologies. This module manages NIOS C(dtc:topology) objects + using the Infoblox WAPI interface over REST. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + name: + description: + - Specifies the DTC Topology display name. + required: true + type: str + rules: + description: + - Configures the topology rules + type: list + elements: dict + suboptions: + dest_type: + description: + - Configures the type of the destination for this DTC Topology Rule. + type: str + choices: + - POOL + - SERVER + required: true + destination_link: + description: + - Configures the name of the destination DTC pool or DTC server. + type: str + return_type: + description: + - Configures the type of the DNS response for the rule. + type: str + choices: + - NOERR + - NXDOMAIN + - REGULAR + default: REGULAR + sources: + description: + - Configures the conditions for matching sources. Should be empty to + set the rule as default destination. + type: list + elements: dict + suboptions: + source_op: + description: + - Configures the operation used to match the value. + type: str + choices: + - IS + - IS_NOT + source_type: + description: + - Configures the source type. + type: str + choices: + - CITY + - CONTINENT + - COUNTRY + - EA0 + - EA1 + - EA2 + - EA3 + - SUBDIVISION + - SUBNET + required: true + source_value: + description: + - Configures the source value. + type: str + required: true + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + state: + description: + - Configures the intended state of the instance of the object on + the NIOS topology. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + default: present + choices: + - present + - absent + type: str +''' + +EXAMPLES = ''' +- name: Configure a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool1 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC1 + - dest_type: POOL + destination_link: web_pool2 + return_type: REGULAR + sources: + - source_op: IS + source_type: EA0 + source_value: DC2 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Add a comment to a DTC topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove a DTC Topology from the system + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_DTC_TOPOLOGY +from ..module_utils.api import normalize_ib_spec + + +def main(): + ''' Main entry point for module execution + ''' + + def sources_transform(sources, module): + source_list = list() + for source in sources: + src = dict([(k, v) for k, v in iteritems(source) if v is not None]) + if 'source_type' not in src or 'source_value' not in src: + module.fail_json(msg='source_type and source_value are required for source') + source_list.append(src) + return source_list + + def rules_transform(module): + rule_list = list() + dest_obj = None + + if not module.params['rules']: + return rule_list + + for rule in module.params['rules']: + if rule['dest_type'] == 'POOL': + dest_obj = wapi.get_object('dtc:pool', {'name': rule['destination_link']}) + else: + dest_obj = wapi.get_object('dtc:server', {'name': rule['destination_link']}) + if not dest_obj and rule['return_type'] == 'REGULAR': + module.fail_json(msg='destination_link %s does not exist' % rule['destination_link']) + + tf_rule = dict( + dest_type=rule['dest_type'], + destination_link=dest_obj[0]['_ref'] if dest_obj else None, + return_type=rule['return_type'] + ) + + if rule['sources']: + tf_rule['sources'] = sources_transform(rule['sources'], module) + + rule_list.append(tf_rule) + return rule_list + + source_spec = dict( + source_op=dict(choices=['IS', 'IS_NOT']), + source_type=dict(required=True, choices=['CITY', 'CONTINENT', 'COUNTRY', 'EA0', 'EA1', 'EA2', 'EA3', 'SUBDIVISION', 'SUBNET']), + source_value=dict(required=True, type='str') + ) + + rule_spec = dict( + dest_type=dict(required=True, choices=['POOL', 'SERVER']), + destination_link=dict(type='str'), + return_type=dict(default='REGULAR', choices=['NOERR', 'NXDOMAIN', 'REGULAR']), + sources=dict(type='list', elements='dict', options=source_spec) + ) + + ib_spec = dict( + name=dict(required=True, ib_req=True), + + rules=dict(type='list', elements='dict', options=rule_spec, transform=rules_transform), + + extattrs=dict(type='dict'), + comment=dict(), + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, + supports_check_mode=True) + + wapi = WapiModule(module) + result = wapi.run(NIOS_DTC_TOPOLOGY, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_fixed_address.py b/plugins/modules/nios_fixed_address.py index f3b099f2..c01d762e 100644 --- a/plugins/modules/nios_fixed_address.py +++ b/plugins/modules/nios_fixed_address.py @@ -16,6 +16,8 @@ - A fixed address is a specific IP address that a DHCP server always assigns when a lease request comes from a particular MAC address of the client. + - A fix address reservation is a specific IP address that a DHCP + server reserves and never assigns to a client. - Supports both IPV4 and IPV6 internet protocols. requirements: - infoblox-client @@ -40,7 +42,8 @@ required: true mac: description: - - The MAC address of the IPv4 interface. + - The MAC address of the IPv4 interface. For a fix address reservation + specify mac address as 00:00:00:00:00:00 type: str duid: description: @@ -131,6 +134,21 @@ password: admin connection: local +- name: Configure an ipv4 dhcp fixed address reservation + infoblox.nios_modules.nios_fixed_address: + name: ipv4_fixed + ipaddr: 192.168.10.1 + mac: 00:00:00:00:00:00 + network: 192.168.10.0/24 + network_view: default + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Configure an ipv6 dhcp fixed address infoblox.nios_modules.nios_fixed_address: name: ipv6_fixed diff --git a/plugins/modules/nios_member.py b/plugins/modules/nios_member.py index 38a6899b..9662c9fb 100644 --- a/plugins/modules/nios_member.py +++ b/plugins/modules/nios_member.py @@ -9,7 +9,9 @@ DOCUMENTATION = ''' --- module: nios_member -author: "Krishna Vasudevan (@krisvasudevan)" +author: + - "Krishna Vasudevan (@krisvasudevan)" + - "Matthew Dennett (@matthewdennett)" short_description: Configure Infoblox NIOS members version_added: "1.0.0" description: @@ -23,7 +25,8 @@ host_name: description: - Specifies the host name of the member to either add or remove from - the NIOS instance. + the NIOS instance. Users can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples. required: true aliases: - name @@ -366,6 +369,13 @@ - Flag for initiating a create token request for pre-provisioned members. type: bool default: False + master_candidate: + description: + - Configures the instance of this object to be enabled as a Grid Master + Candidate or a regular member node. + - True enables the member as a Master Candidate + type: bool + default: false state: description: - Configures the intended state of the instance of the object on @@ -397,6 +407,41 @@ password: admin connection: local +- name: Add a Grid Master Candidate to the grid with IPv4 address + infoblox.nios_modules.nios_member: + host_name: member01.localdomain + master_candidate: true + vip_setting: + - address: 192.168.1.100 + subnet_mask: 255.255.255.0 + gateway: 192.168.1.1 + config_addr_type: IPV4 + platform: VNIOS + comment: "Created by Ansible" + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Update host name of member + infoblox.nios_modules.nios_member: + host_name: {old_name: block1.localdomain, new_name: member01.localdomain} + master_candidate: false + vip_setting: + - address: 120.0.0.25 + subnet_mask: 255.255.255.0 + gateway: 120.0.0.1 + config_addr_type: IPV4 + platform: VNIOS + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Add a HA member to the grid infoblox.nios_modules.nios_member: host_name: memberha.localdomain @@ -457,7 +502,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_MEMBER from ..module_utils.api import normalize_ib_spec @@ -553,6 +597,7 @@ def main(): pre_provisioning=dict(type='list', elements='dict', options=pre_prov_spec), extattrs=dict(type='dict'), create_token=dict(type='bool', default=False), + master_candidate=dict(type='bool', default=False) ) argument_spec = dict( diff --git a/plugins/modules/nios_mx_record.py b/plugins/modules/nios_mx_record.py index 1ff3bc8a..98b4cba0 100644 --- a/plugins/modules/nios_mx_record.py +++ b/plugins/modules/nios_mx_record.py @@ -25,7 +25,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. Users can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples. type: str required: true view: @@ -103,6 +104,18 @@ password: admin connection: local +- name: Update name of MX Record + infoblox.nios_modules.nios_mx_record: + name: {old_name: ansible.com, new_name: newAnsible.com} + mx: mailhost.ansible.com + preference: 0 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Remove an MX record from the system infoblox.nios_modules.nios_mx_record: name: ansible.com @@ -119,7 +132,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_MX_RECORD from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_naptr_record.py b/plugins/modules/nios_naptr_record.py index aa59921b..47aa9bdf 100644 --- a/plugins/modules/nios_naptr_record.py +++ b/plugins/modules/nios_naptr_record.py @@ -148,7 +148,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_network.py b/plugins/modules/nios_network.py index e53782dd..d9f6040a 100644 --- a/plugins/modules/nios_network.py +++ b/plugins/modules/nios_network.py @@ -9,7 +9,9 @@ DOCUMENTATION = ''' --- module: nios_network -author: "Peter Sprygada (@privateip)" +author: + - "Peter Sprygada (@privateip)" + - "Matthew Dennett (@matthewdennett)" short_description: Configure Infoblox NIOS network object version_added: "1.0.0" description: @@ -95,6 +97,20 @@ - If set to true it'll create the network container to be added or removed from the system. type: bool + members: + description: + - Configures the Nios Menber assignment for the configured network instance. + This argument accepts a list of member names (see suboptions). When omitted + a default value of an empty list is used. If the field 'container' is set to + true this field is ignored. + type: list + default: [] + elements: dict + suboptions: + name: + description: + - The name of the Nios member to be assigned to this network. + type: str state: description: - Configures the intended state of the instance of the object on @@ -131,6 +147,31 @@ password: admin connection: local +- name: Create network with member assignment for a network ipv4 + infoblox.nios_modules.nios_network: + network: 192.168.10.0/24 + comment: This is a test comment + members: + - name: member1.infoblox + - name: member2.infoblox + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Remove member assignment form ipv4 network + infoblox.nios_modules.nios_network: + network: 192.168.10.0/24 + comment: This is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Set dhcp options for a network ipv4 infoblox.nios_modules.nios_network: network: 192.168.10.0/24 @@ -287,7 +328,8 @@ def main(): template=dict(type='str'), extattrs=dict(type='dict'), comment=dict(), - container=dict(type='bool', ib_req=True) + container=dict(type='bool', ib_req=True), + members=dict(type='list', elements='dict', default=[]) ) argument_spec = dict( diff --git a/plugins/modules/nios_nsgroup.py b/plugins/modules/nios_nsgroup.py index e9904212..91e5d6d4 100644 --- a/plugins/modules/nios_nsgroup.py +++ b/plugins/modules/nios_nsgroup.py @@ -405,7 +405,7 @@ def grid_secondaries_preferred_primaries_transform(module): enable_preferred_primaries=dict(type='bool', default=False), grid_replicate=dict(type='bool', default=False), lead=dict(type='bool', default=False), - preferred_primaries=dict(type='list', elements='dict', options=extserver_spec, default=[]), + preferred_primaries=dict(type='list', elements='dict', options=extserver_spec, default=None), stealth=dict(type='bool', default=False), ) diff --git a/plugins/modules/nios_range.py b/plugins/modules/nios_range.py new file mode 100644 index 00000000..0f1b5cf9 --- /dev/null +++ b/plugins/modules/nios_range.py @@ -0,0 +1,407 @@ +#!/usr/bin/python +# Copyright (c) 2018-2019 Red Hat, Inc. +# Copyright (c) 2020 Infoblox, Inc. +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +--- +module: nios_range +author: "Matthew Dennett (@matthewdennett)" +short_description: Configure Infoblox NIOS network range object +version_added: "1.4.0" +description: + - Adds and/or removes instances of range objects from + Infoblox NIOS servers. This module manages NIOS DHCP range objects + using the Infoblox WAPI interface over REST. + - Supports both IPV4 and IPV6 internet protocols. +requirements: + - infoblox-client +extends_documentation_fragment: infoblox.nios_modules.nios +notes: + - This module supports C(check_mode). +options: + network: + description: + - Specifies the network to add or remove DHCP range to. The value + should use CIDR notation. + type: str + required: true + aliases: + - cidr + network_view: + description: + - Configures the name of the network view to associate with this + configured instance. + type: str + default: default + options: + description: + - Configures the set of DHCP options to be included as part of + the configured network instance. This argument accepts a list + of values (see suboptions). When configuring suboptions at + least one of C(name) or C(num) must be specified. + type: list + elements: dict + suboptions: + name: + description: + - The name of the DHCP option to configure. The standard options are + C(router), C(router-templates), C(domain-name-servers), C(domain-name), + C(broadcast-address), C(broadcast-address-offset), C(dhcp-lease-time), + and C(dhcp6.name-servers). + type: str + num: + description: + - The number of the DHCP option to configure + type: int + value: + description: + - The value of the DHCP option specified by C(name) + type: str + required: true + use_option: + description: + - Only applies to a subset of options (see NIOS API documentation) + type: bool + default: 'yes' + vendor_class: + description: + - The name of the space this DHCP option is associated to + type: str + default: DHCP + extattrs: + description: + - Allows for the configuration of Extensible Attributes on the + instance of the object. This argument accepts a set of key / value + pairs for configuration. + type: dict + comment: + description: + - Configures a text string comment to be associated with the instance + of this object. The provided text string will be configured on the + object instance. + type: str + start_addr: + description: + - Configures IP address this object instance is to begin from. If + 'new_start_addr' is defined during a create operation this value is + overridden with the value of 'new_start_addr' + type: str + required: true + aliases: + - start + - first_addr + - first + new_start_addr: + description: + - Configures IP address to update this object instance to begin from. + type: str + required: false + aliases: + - new_start + - new_first_addr + - new_first + end_addr: + description: + - Configures IP address this object instance is to end at. If + 'new_end_addr' is defined during a create operation this value is + overridden with the value of 'new_end_addr' + type: str + required: true + aliases: + - end + - last_addr + - last + new_end_addr: + description: + - Configures IP address to update this object instance to end at. + type: str + required: false + aliases: + - new_end + - new_last_addr + - new_last + member: + description: + - The hostname of the Nios member which will be configured to server + this object instance. Can not be configured when 'ms_server' or + 'failover_association' are configured. + type: str + required: false + failover_association: + description: + - The name of the DHCP failover association which will be configured + to server this object instance. A failover of MS or Nios members + can be configured. Can not be configured when 'ms_server' or + 'member' are configured. + type: str + required: false + ms_server: + description: + - The hostname of the MS member which will be configured to server + this object instance. Can not be configured when 'member' or + 'failover_association' are configured. + type: str + required: false + server_association_type: + description: + - Configured the type of server association that will be assigned to + serve this object instance. This value is not required and will be + set as needed automatically during module execution. + type: str + required: false + choices: + - NONE + - FAILOVER + - MEMBER + - FAILOVER_MS + - MS_SERVER + state: + description: + - Configures the intended state of the instance of the object on + the NIOS server. When this value is set to C(present), the object + is configured on the device and when this value is set to C(absent) + the value is removed (if necessary) from the device. + type: str + default: present + choices: + - present + - absent + disable: + description: + - Determines whether a range is disabled or not. When this is set + to False, the range is enabled. + type: bool + default: false + name: + description: + - Congifured the name of the Microsoft scope for the instance of the + object on the NIOS server. + type: str +''' + +EXAMPLES = ''' + +- name: Configure a ipv4 reserved range + infoblox.nios_modules.nios_range: + network: 192.168.10.0/24 + start: 192.168.10.10 + end: 192.168.10.20 + name: Test Range 1 + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Upadtes a ipv4 reserved range + infoblox.nios_modules.nios_range: + network: 192.168.10.0/24 + start: 192.168.10.10 + new_start: 192.168.10.5 + end: 192.168.10.20 + new_end: 192.168.10.50 + name: Test Range 1 + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Configure a ipv4 range served by a member + infoblox.nios_modules.nios_range: + network: 192.168.10.0/24 + start: 192.168.10.10 + end: 192.168.10.20 + name: Test Range 1 + member: infoblox1.localdomain + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Configure a ipv4 range served by a failover association + infoblox.nios_modules.nios_range: + network: 192.168.10.0/24 + start: 192.168.10.10 + end: 192.168.10.20 + name: Test Range 1 + failover_association: fo_association_01 + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Configure a ipv4 range with options + infoblox.nios_modules.nios_range: + network: 18.10.0.0/24 + network_view: custom + start_addr: 18.10.0.12 + end_addr: 18.10.0.14 + options: + - name: domain-name + value: zone1.com + comment: Created with Ansible + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + +- name: Configure a ipv4 range served by a MS Server + infoblox.nios_modules.nios_range: + network: 192.168.10.0/24 + start: 192.168.10.10 + end: 192.168.10.20 + name: Test Range 1 + ms_server: dc01.ad.localdomain + comment: this is a test comment + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local +''' + +RETURN = ''' # ''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.six import iteritems +from ..module_utils.api import WapiModule +from ..module_utils.api import NIOS_RANGE +from ..module_utils.api import normalize_ib_spec + + +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: , + num: , + value: , + use_option: , + vendor_class: + } + 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 + ''' + 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') + options.append(opt) + return options + + +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): + for temp_dict in module.params[key]: + if 'num' in temp_dict: + if temp_dict['num'] in (43, 124, 125, 67, 60): + del temp_dict['use_option'] + return ib_spec + + +def convert_range_member_to_struct(module): + '''This function will check the module input to ensure that only one member assignment type is specified at once. + Member passed in is converted to the correct struct for the API to understand bassed on the member type. + ''' + # Error checking that only one member type was defined + params = [k for k in module.params.keys() if module.params[k] is not None] + opts = list(set(params).intersection(['member', 'failover_association', 'ms_server'])) + if len(opts) > 1: + raise AttributeError("'%s' can not be defined when '%s' is defined!" % (opts[0], opts[1])) + + # A member node was passed in. Ehsure the correct type and struct + if 'member' in opts: + module.params['member'] = {'_struct': 'dhcpmember', 'name': module.params['member']} + module.params['server_association_type'] = 'MEMBER' + # A FO association was passed in. Ensure the correct type is set + elif 'failover_association' in opts: + module.params['server_association_type'] = 'FAILOVER' + # MS server was passed in. Ensure the correct type and struct + elif 'ms_server' in opts: + module.params['ms_server'] = {'_struct': 'msdhcpserver', 'ipv4addr': module.params['ms_server']} + module.params['server_association_type'] = 'MS_SERVER' + else: + module.params['server_association_type'] = 'NONE' + return module + + +def main(): + ''' Main entry point for module execution + ''' + option_spec = dict( + # one of name or num is required; enforced by the function options() + name=dict(), + num=dict(type='int'), + + value=dict(required=True), + + use_option=dict(type='bool', default=True), + vendor_class=dict(default='DHCP') + ) + + # This is what gets posted to the WAPI API + ib_spec = dict( + network=dict(required=True, aliases=['cidr']), + network_view=dict(default='default', ib_req=True), + start_addr=dict(required=True, aliases=['start', 'first_addr', 'first'], type='str', ib_req=True), + new_start_addr=dict(aliases=['new_start', 'new_first_addr', 'new_first'], type='str'), + end_addr=dict(required=True, aliases=['end', 'last_addr', 'last'], type='str', ib_req=True), + new_end_addr=dict(aliases=['new_end', 'new_last_addr', 'new_last'], type='str'), + name=dict(type='str'), + disable=dict(type='bool', default='false',), + options=dict(type='list', elements='dict', options=option_spec, transform=options), + member=dict(type='str'), + failover_association=dict(type='str'), + ms_server=dict(type='str'), + server_association_type=dict(type='str', choices=['NONE', 'FAILOVER', 'MEMBER', 'FAILOVER_MS', 'MS_SERVER']), + extattrs=dict(type='dict'), + comment=dict() + ) + + argument_spec = dict( + provider=dict(required=True), + state=dict(default='present', choices=['present', 'absent']) + ) + + argument_spec.update(normalize_ib_spec(ib_spec)) + argument_spec.update(WapiModule.provider_spec) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + module = convert_range_member_to_struct(module) + wapi = WapiModule(module) + # to check for vendor specific dhcp option + ib_spec = check_vendor_specific_dhcp_option(module, ib_spec) + + result = wapi.run(NIOS_RANGE, ib_spec) + + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/nios_restartservices.py b/plugins/modules/nios_restartservices.py index b8f0bc49..c27b2462 100644 --- a/plugins/modules/nios_restartservices.py +++ b/plugins/modules/nios_restartservices.py @@ -90,7 +90,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_srv_record.py b/plugins/modules/nios_srv_record.py index 9ac94577..86e665c5 100644 --- a/plugins/modules/nios_srv_record.py +++ b/plugins/modules/nios_srv_record.py @@ -25,7 +25,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. Users can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples. required: true type: str view: @@ -111,6 +112,20 @@ password: admin connection: local +- name: Update name of SRV record + infoblox.nios_modules.nios_srv_record: + name: {old_name: _sip._tcp.service.ansible.com, new_name: _sip._udp.service.ansible.com} + port: 5080 + priority: 10 + target: service1.ansible.com + weight: 10 + state: present + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Remove an SRV record from the system infoblox.nios_modules.nios_srv_record: name: _sip._tcp.service.ansible.com @@ -129,7 +144,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import NIOS_SRV_RECORD from ..module_utils.api import normalize_ib_spec diff --git a/plugins/modules/nios_txt_record.py b/plugins/modules/nios_txt_record.py index 51e4504c..7e46ed97 100644 --- a/plugins/modules/nios_txt_record.py +++ b/plugins/modules/nios_txt_record.py @@ -25,7 +25,8 @@ name: description: - Specifies the fully qualified hostname to add or remove from - the system. + the system. Users can also update the name as it is possible + to pass a dict containing I(new_name), I(old_name). See examples. required: true type: str view: @@ -85,6 +86,18 @@ username: admin password: admin + - name: Update name of TXT record + infoblox.nios_modules.nios_txt_record: + name: {old_name: sample.txtrecord.com, new_name: newsample.txtrecord.com} + text: mytext + state: present + view: External + provider: + host: "{{ inventory_hostname_short }}" + username: admin + password: admin + connection: local + - name: Ensure a text Record does not exist infoblox.nios_modules.nios_txt_record: name: fqdn.txt.record.com @@ -100,7 +113,6 @@ RETURN = ''' # ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import iteritems from ..module_utils.api import WapiModule from ..module_utils.api import normalize_ib_spec diff --git a/requirements.txt b/requirements.txt index be611454..886ac909 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -infoblox-client +infoblox-client==0.6.0 \ No newline at end of file diff --git a/tests/integration/targets/nios_a_record/tasks/main.yml b/tests/integration/targets/nios_a_record/tasks/main.yml index b3fa8014..0955a39f 100644 --- a/tests/integration/targets/nios_a_record/tasks/main.yml +++ b/tests/integration/targets/nios_a_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_a_record_idempotence.yml +- include_tasks: nios_a_record_idempotence.yml diff --git a/tests/integration/targets/nios_aaaa_record/tasks/main.yml b/tests/integration/targets/nios_aaaa_record/tasks/main.yml index 2fec2adb..9096b63d 100644 --- a/tests/integration/targets/nios_aaaa_record/tasks/main.yml +++ b/tests/integration/targets/nios_aaaa_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_aaaa_record_idempotence.yml +- include_tasks: nios_aaaa_record_idempotence.yml diff --git a/tests/integration/targets/nios_cname_record/tasks/main.yml b/tests/integration/targets/nios_cname_record/tasks/main.yml index b30f250a..df8ff758 100644 --- a/tests/integration/targets/nios_cname_record/tasks/main.yml +++ b/tests/integration/targets/nios_cname_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_cname_record_idempotence.yml +- include_tasks: nios_cname_record_idempotence.yml diff --git a/tests/integration/targets/nios_dns_view/tasks/main.yml b/tests/integration/targets/nios_dns_view/tasks/main.yml index 1eb9c07a..2b9ca3a0 100644 --- a/tests/integration/targets/nios_dns_view/tasks/main.yml +++ b/tests/integration/targets/nios_dns_view/tasks/main.yml @@ -1 +1 @@ -- include: nios_dns_view_idempotence.yml +- include_tasks: nios_dns_view_idempotence.yml diff --git a/tests/integration/targets/nios_dtc_monitor_http/aliases b/tests/integration/targets/nios_dtc_monitor_http/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml new file mode 100644 index 00000000..f774bfbf --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_http_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml new file mode 100644 index 00000000..8b3a4f40 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_http/tasks/nios_dtc_monitor_http_idempotence.yaml @@ -0,0 +1,75 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_create1 + +- name: Recreate a DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + port: 443 + secure: true + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_create2 + +- name: Add a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_update1 + +- name: Readd a comment to an existing DTC HTTPS monitor + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_http_update2 + +- name: Remove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_http_delete1 + +- name: Reremove a DTC HTTPS monitor from the system + infoblox.nios_modules.nios_dtc_monitor_http: + name: https_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_http_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_http_create1.changed" + - "not dtc_monitor_http_create2.changed" + - "dtc_monitor_http_update1.changed" + - "not dtc_monitor_http_update2.changed" + - "dtc_monitor_http_delete1.changed" + - "not dtc_monitor_http_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/aliases b/tests/integration/targets/nios_dtc_monitor_icmp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml new file mode 100644 index 00000000..28bf85bd --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_icmp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml new file mode 100644 index 00000000..984aa59a --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_icmp/tasks/nios_dtc_monitor_icmp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_create1 + +- name: Recreate a DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_create2 + +- name: Add a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_update1 + +- name: Readd a comment to an existing DTC ICMP monitor + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_update2 + +- name: Remove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_delete1 + +- name: Reremove a DTC ICMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_icmp: + name: icmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_icmp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_icmp_create1.changed" + - "not dtc_monitor_icmp_create2.changed" + - "dtc_monitor_icmp_update1.changed" + - "not dtc_monitor_icmp_update2.changed" + - "dtc_monitor_icmp_delete1.changed" + - "not dtc_monitor_icmp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/aliases b/tests/integration/targets/nios_dtc_monitor_pdp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml new file mode 100644 index 00000000..55829c8d --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_pdp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml new file mode 100644 index 00000000..022f12d7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_pdp/tasks/nios_dtc_monitor_pdp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_create1 + +- name: Recreate a DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_create2 + +- name: Add a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_update1 + +- name: Readd a comment to an existing DTC PDP monitor + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_update2 + +- name: Remove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_delete1 + +- name: Reremove a DTC PDP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_pdp: + name: pdp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_pdp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_pdp_create1.changed" + - "not dtc_monitor_pdp_create2.changed" + - "dtc_monitor_pdp_update1.changed" + - "not dtc_monitor_pdp_update2.changed" + - "dtc_monitor_pdp_delete1.changed" + - "not dtc_monitor_pdp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_sip/aliases b/tests/integration/targets/nios_dtc_monitor_sip/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml new file mode 100644 index 00000000..e5e1b33f --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_sip_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml new file mode 100644 index 00000000..68187a12 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_sip/tasks/nios_dtc_monitor_sip_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_create1 + +- name: Recreate a DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_create2 + +- name: Add a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_update1 + +- name: Readd a comment to an existing DTC SIP monitor + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_update2 + +- name: Remove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_delete1 + +- name: Reremove a DTC SIP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_sip: + name: sip_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_sip_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_sip_create1.changed" + - "not dtc_monitor_sip_create2.changed" + - "dtc_monitor_sip_update1.changed" + - "not dtc_monitor_sip_update2.changed" + - "dtc_monitor_sip_delete1.changed" + - "not dtc_monitor_sip_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/aliases b/tests/integration/targets/nios_dtc_monitor_snmp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml new file mode 100644 index 00000000..02c852d3 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_snmp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml new file mode 100644 index 00000000..12b56047 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_snmp/tasks/nios_dtc_monitor_snmp_idempotence.yaml @@ -0,0 +1,71 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_create1 + +- name: Recreate a DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_create2 + +- name: Add a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_update1 + +- name: Readd a comment to an existing DTC SNMP monitor + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_update2 + +- name: Remove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_delete1 + +- name: Reremove a DTC SNMP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_snmp: + name: snmp_monitor + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_snmp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_snmp_create1.changed" + - "not dtc_monitor_snmp_create2.changed" + - "dtc_monitor_snmp_update1.changed" + - "not dtc_monitor_snmp_update2.changed" + - "dtc_monitor_snmp_delete1.changed" + - "not dtc_monitor_snmp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/aliases b/tests/integration/targets/nios_dtc_monitor_tcp/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml new file mode 100644 index 00000000..e24c8265 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_monitor_tcp_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml new file mode 100644 index 00000000..1c025b93 --- /dev/null +++ b/tests/integration/targets/nios_dtc_monitor_tcp/tasks/nios_dtc_monitor_tcp_idempotence.yaml @@ -0,0 +1,78 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: absent + provider: "{{ nios_provider }}" + +- name: Create a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_create1 + +- name: Recreate a DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_create2 + +- name: Add a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_update1 + +- name: Readd a comment to an existing DTC TCP monitor + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_update2 + +- name: Remove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_delete1 + +- name: Reremove a DTC TCP monitor from the system + infoblox.nios_modules.nios_dtc_monitor_tcp: + name: tcp_monitor + port: 8080 + state: absent + provider: "{{ nios_provider }}" + register: dtc_monitor_tcp_delete2 + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_monitor_tcp_create1.changed" + - "not dtc_monitor_tcp_create2.changed" + - "dtc_monitor_tcp_update1.changed" + - "not dtc_monitor_tcp_update2.changed" + - "dtc_monitor_tcp_delete1.changed" + - "not dtc_monitor_tcp_delete2.changed" diff --git a/tests/integration/targets/nios_dtc_topology/aliases b/tests/integration/targets/nios_dtc_topology/aliases new file mode 100644 index 00000000..b3138dc7 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/aliases @@ -0,0 +1,3 @@ +shippable/cloud/group1 +cloud/nios +destructive diff --git a/tests/integration/targets/nios_dtc_topology/defaults/main.yaml b/tests/integration/targets/nios_dtc_topology/defaults/main.yaml new file mode 100644 index 00000000..9ef5ba51 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "*" +test_items: [] diff --git a/tests/integration/targets/nios_dtc_topology/meta/main.yaml b/tests/integration/targets/nios_dtc_topology/meta/main.yaml new file mode 100644 index 00000000..1b01a972 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: + - prepare_nios_tests diff --git a/tests/integration/targets/nios_dtc_topology/tasks/main.yaml b/tests/integration/targets/nios_dtc_topology/tasks/main.yaml new file mode 100644 index 00000000..8873ef55 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/tasks/main.yaml @@ -0,0 +1 @@ +- include_tasks: nios_dtc_topology_idempotence.yaml diff --git a/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml b/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml new file mode 100644 index 00000000..a24a9c31 --- /dev/null +++ b/tests/integration/targets/nios_dtc_topology/tasks/nios_dtc_topology_idempotence.yaml @@ -0,0 +1,122 @@ +- name: Clean up the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: absent + provider: "{{ nios_provider }}" + +- name: Create the parent object + infoblox.nios_modules.nios_zone: + name: ansible.com + state: present + provider: "{{ nios_provider }}" + +- name: Clean up the DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + +- name: Clean up the DTC pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + state: absent + provider: "{{ nios_provider }}" + +- name: Clean up the DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + state: absent + provider: "{{ nios_provider }}" + +- name: Create DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" + +- name: Create DTC Pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + servers: + - server: Server1 + ratio: 1 + comment: Created with Ansible + state: present + provider: "{{ nios_provider }}" + +- name: Create a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + rules: + - dest_type: POOL + destination_link: web_pool + return_type: REGULAR + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_create1 + +- name: Recreate a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_create2 + +- name: Add a comment to an existing DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_update1 + +- name: Readd a comment to an existing DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + comment: this is a test comment + state: present + provider: "{{ nios_provider }}" + register: dtc_topology_update2 + +- name: Remove a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + register: dtc_topology_delete1 + +- name: Reremove a DTC Topology + infoblox.nios_modules.nios_dtc_topology: + name: a_topology + state: absent + provider: "{{ nios_provider }}" + register: dtc_topology_delete2 + +- name: Remove the DTC pool + infoblox.nios_modules.nios_dtc_pool: + name: web_pool + lb_preferred_method: ROUND_ROBIN + state: absent + provider: "{{ nios_provider }}" + +- name: Remove the DTC server + infoblox.nios_modules.nios_dtc_server: + name: Server1 + host: 192.168.10.1 + state: absent + provider: "{{ nios_provider }}" + +- name: Verify outcomes + ansible.builtin.assert: + that: + - "dtc_topology_create1.changed" + - "not dtc_topology_create2.changed" + - "dtc_topology_update1.changed" + - "not dtc_topology_update2.changed" + - "dtc_topology_delete1.changed" + - "not dtc_topology_delete2.changed" diff --git a/tests/integration/targets/nios_host_record/tasks/main.yml b/tests/integration/targets/nios_host_record/tasks/main.yml index 2f1dcc55..3c626f55 100644 --- a/tests/integration/targets/nios_host_record/tasks/main.yml +++ b/tests/integration/targets/nios_host_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_host_record_idempotence.yml +- include_tasks: nios_host_record_idempotence.yml diff --git a/tests/integration/targets/nios_mx_record/tasks/main.yml b/tests/integration/targets/nios_mx_record/tasks/main.yml index fe687173..ebffb41a 100644 --- a/tests/integration/targets/nios_mx_record/tasks/main.yml +++ b/tests/integration/targets/nios_mx_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_mx_record_idempotence.yml +- include_tasks: nios_mx_record_idempotence.yml diff --git a/tests/integration/targets/nios_naptr_record/tasks/main.yml b/tests/integration/targets/nios_naptr_record/tasks/main.yml index a22a8018..ed94e8a3 100644 --- a/tests/integration/targets/nios_naptr_record/tasks/main.yml +++ b/tests/integration/targets/nios_naptr_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_naptr_record_idempotence.yml +- include_tasks: nios_naptr_record_idempotence.yml diff --git a/tests/integration/targets/nios_network/tasks/main.yml b/tests/integration/targets/nios_network/tasks/main.yml index c147af8f..040cb8a8 100644 --- a/tests/integration/targets/nios_network/tasks/main.yml +++ b/tests/integration/targets/nios_network/tasks/main.yml @@ -1 +1 @@ -- include: nios_network_idempotence.yml +- include_tasks: nios_network_idempotence.yml diff --git a/tests/integration/targets/nios_network_view/tasks/main.yml b/tests/integration/targets/nios_network_view/tasks/main.yml index 97e87148..0acf4a4c 100644 --- a/tests/integration/targets/nios_network_view/tasks/main.yml +++ b/tests/integration/targets/nios_network_view/tasks/main.yml @@ -1 +1 @@ -- include: nios_network_view_idempotence.yml +- include_tasks: nios_network_view_idempotence.yml diff --git a/tests/integration/targets/nios_ptr_record/tasks/main.yml b/tests/integration/targets/nios_ptr_record/tasks/main.yml index ec33e8f5..29fbb5fe 100644 --- a/tests/integration/targets/nios_ptr_record/tasks/main.yml +++ b/tests/integration/targets/nios_ptr_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_ptr_record_idempotence.yml +- include_tasks: nios_ptr_record_idempotence.yml diff --git a/tests/integration/targets/nios_srv_record/tasks/main.yml b/tests/integration/targets/nios_srv_record/tasks/main.yml index 1c847673..4e4dd166 100644 --- a/tests/integration/targets/nios_srv_record/tasks/main.yml +++ b/tests/integration/targets/nios_srv_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_srv_record_idempotence.yml +- include_tasks: nios_srv_record_idempotence.yml diff --git a/tests/integration/targets/nios_txt_record/tasks/main.yml b/tests/integration/targets/nios_txt_record/tasks/main.yml index e15b4c55..0acbc091 100644 --- a/tests/integration/targets/nios_txt_record/tasks/main.yml +++ b/tests/integration/targets/nios_txt_record/tasks/main.yml @@ -1 +1 @@ -- include: nios_txt_record_idempotence.yml +- include_tasks: nios_txt_record_idempotence.yml diff --git a/tests/integration/targets/nios_zone/tasks/main.yml b/tests/integration/targets/nios_zone/tasks/main.yml index f066edcd..cb335970 100644 --- a/tests/integration/targets/nios_zone/tasks/main.yml +++ b/tests/integration/targets/nios_zone/tasks/main.yml @@ -1 +1 @@ -- include: nios_zone_idempotence.yml +- include_tasks: nios_zone_idempotence.yml diff --git a/tests/integration/targets/prepare_nios_tests/tasks/main.yml b/tests/integration/targets/prepare_nios_tests/tasks/main.yml index 2a3092f3..e3c03fb3 100644 --- a/tests/integration/targets/prepare_nios_tests/tasks/main.yml +++ b/tests/integration/targets/prepare_nios_tests/tasks/main.yml @@ -1 +1 @@ -- include: prepare_nios_tests_idempotence.yml +- include_tasks: prepare_nios_tests_idempotence.yml diff --git a/tests/requirements.txt b/tests/requirements.txt index 7f835e9f..708b417d 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -4,6 +4,6 @@ pytest-xdist mock pytest-mock pytest-cov==2.8.0 -coverage +coverage==7.3.2 pygobject launchpadlib diff --git a/tests/unit/plugins/module_utils/test_api.py b/tests/unit/plugins/module_utils/test_api.py index f43c8da6..18d02faf 100644 --- a/tests/unit/plugins/module_utils/test_api.py +++ b/tests/unit/plugins/module_utils/test_api.py @@ -5,8 +5,10 @@ __metaclass__ = type import copy - -from ansible_collections.infoblox.nios_modules.tests.unit.compat import unittest +try: + from ansible_collections.infoblox.nios_modules.tests.unit.compat import unittest +except ImportError: + import unittest from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock from ansible_collections.infoblox.nios_modules.plugins.module_utils import api @@ -22,7 +24,7 @@ def setUp(self): self.mock_connector = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.get_connector') self.mock_connector.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -32,7 +34,7 @@ def tearDown(self): self.mock_check_type_dict.stop() def test_get_provider_spec(self): - provider_options = ['host', 'username', 'password', 'validate_certs', 'silent_ssl_warnings', + provider_options = ['host', 'username', 'password', 'cert', 'key', 'validate_certs', 'silent_ssl_warnings', 'http_request_timeout', 'http_pool_connections', 'http_pool_maxsize', 'max_retries', 'wapi_version', 'max_results'] res = api.WapiBase.provider_spec @@ -58,7 +60,7 @@ def test_wapi_no_change(self): { "comment": "test comment", "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": self.mock_check_type_dict_obj().__getitem__(), + "name": 'default', "extattrs": {} } ] @@ -146,7 +148,7 @@ def test_wapi_extattrs_change(self): kwargs = copy.deepcopy(test_object[0]) kwargs['extattrs']['Site']['value'] = 'update' - kwargs['name'] = self.mock_check_type_dict_obj().__getitem__() + kwargs['name'] = 'default' del kwargs['_ref'] wapi = self._get_wapi(test_object) @@ -162,7 +164,7 @@ def test_wapi_extattrs_nochange(self): test_object = [{ "comment": "test comment", "_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", - "name": self.mock_check_type_dict_obj().__getitem__(), + "name": "default", "extattrs": {'Site': {'value': 'test'}} }] @@ -193,7 +195,7 @@ def test_wapi_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__()}) + wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible'}) def test_wapi_delete(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible', @@ -243,7 +245,7 @@ def test_wapi_strip_network_view(self): kwargs = test_object[0].copy() ref = kwargs.pop('_ref') kwargs['comment'] = 'updated comment' - kwargs['name'] = self.mock_check_type_dict_obj().__getitem__() + kwargs['name'] = 'ansible' del kwargs['network_view'] del kwargs['extattrs'] diff --git a/tests/unit/plugins/modules/test_nios_a_record.py b/tests/unit/plugins/modules/test_nios_a_record.py index 6921d967..16d81866 100644 --- a/tests/unit/plugins/modules/test_nios_a_record.py +++ b/tests/unit/plugins/modules/test_nios_a_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_a_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -79,7 +79,7 @@ def test_nios_a_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': 'a.ansible.com', 'ipv4': '192.168.10.1'}) def test_nios_a_record_update_comment(self): diff --git a/tests/unit/plugins/modules/test_nios_aaaa_record.py b/tests/unit/plugins/modules/test_nios_aaaa_record.py index d9dce970..1b4f96c0 100644 --- a/tests/unit/plugins/modules/test_nios_aaaa_record.py +++ b/tests/unit/plugins/modules/test_nios_aaaa_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_aaaa_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -79,7 +79,7 @@ def test_nios_aaaa_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': 'aaaa.ansible.com', 'ipv6': '2001:0db8:85a3:0000:0000:8a2e:0370:7334'}) def test_nios_aaaa_record_update_comment(self): diff --git a/tests/unit/plugins/modules/test_nios_cname_record.py b/tests/unit/plugins/modules/test_nios_cname_record.py index bbf56172..360a9cc9 100644 --- a/tests/unit/plugins/modules/test_nios_cname_record.py +++ b/tests/unit/plugins/modules/test_nios_cname_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_cname_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -61,7 +61,7 @@ def load_fixtures(self, commands=None): self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) self.load_config.return_value = dict(diff=None, session='session') - def test_nios_a_record_create(self): + def test_nios_cname_record_create(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com', 'comment': None, 'extattrs': None} @@ -79,10 +79,10 @@ def test_nios_a_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com'}) - def test_nios_a_record_update_comment(self): + def test_nios_cname_record_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com', 'comment': 'updated comment', 'extattrs': None} @@ -108,7 +108,7 @@ def test_nios_a_record_update_comment(self): self.assertTrue(res['changed']) - def test_nios_a_record_remove(self): + def test_nios_cname_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com', 'comment': None, 'extattrs': None} diff --git a/tests/unit/plugins/modules/test_nios_dns_view.py b/tests/unit/plugins/modules/test_nios_dns_view.py index cc874611..b4933b55 100644 --- a/tests/unit/plugins/modules/test_nios_dns_view.py +++ b/tests/unit/plugins/modules/test_nios_dns_view.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dns_view.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -78,7 +78,7 @@ def test_nios_dns_view_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__()}) + wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible-dns'}) def test_nios_dns_view_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible-dns', diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py new file mode 100644 index 00000000..d053f0bf --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py @@ -0,0 +1,136 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_http +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcHttpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_http + + def setUp(self): + super(TestNiosDtcHttpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcHttpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_http_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'port': 443, 'secure': True, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "secure": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'https_monitor', + 'port': 443, 'secure': True}) + + def test_nios_dtc_monitor_http_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_http_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'https_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py new file mode 100644 index 00000000..fb4b300d --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_icmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcIcmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_icmp + + def setUp(self): + super(TestNiosDtcIcmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcIcmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_icmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'icmp_monitor'}) + + def test_nios_dtc_monitor_icmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_icmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py new file mode 100644 index 00000000..80263784 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py @@ -0,0 +1,131 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_pdp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_pdp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_pdp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'pdp_monitor'}) + + def test_nios_dtc_monitor_pdp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_pdp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py new file mode 100644 index 00000000..90b86bfa --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_sip +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSipMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_sip + + def setUp(self): + super(TestNiosDtcSipMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSipMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_sip_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'sip_monitor'}) + + def test_nios_dtc_monitor_sip_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_sip_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py new file mode 100644 index 00000000..838a35eb --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py @@ -0,0 +1,143 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_snmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSnmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_snmp + + def setUp(self): + super(TestNiosDtcSnmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSnmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_snmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'snmp_monitor'}) + + def test_nios_dtc_monitor_snmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_snmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py new file mode 100644 index 00000000..072ba1a3 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py @@ -0,0 +1,133 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_tcp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_tcp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_tcp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'port': 8080, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'tcp_monitor', + 'port': 8080}) + + def test_nios_dtc_monitor_tcp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_tcp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'tcp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_dtc_topology.py b/tests/unit/plugins/modules/test_nios_dtc_topology.py new file mode 100644 index 00000000..d0ee4c69 --- /dev/null +++ b/tests/unit/plugins/modules/test_nios_dtc_topology.py @@ -0,0 +1,156 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_topology +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTopologyModule(TestNiosModule): + + module = nios_dtc_topology + + def setUp(self): + super(TestNiosDtcTopologyModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTopologyModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_topology_create(self): + self.module.params = { + 'provider': None, + 'state': 'present', + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }], + 'comment': None, + 'extattrs': None + } + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "rules": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with( + 'testobject', + { + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }] + } + ) + + def test_nios_dtc_topology_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'a_topology', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + '_ref': 'dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true', + 'name': 'a_topology', + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + 'comment': "test comment", + 'extattrs': {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_topology_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'a_topology', + 'comment': None, 'extattrs': None} + + ref = "dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": {}, + "_ref": ref, + "name": "a_topology", + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/tests/unit/plugins/modules/test_nios_host_record.py b/tests/unit/plugins/modules/test_nios_host_record.py index ddb8a265..8a5a8e6f 100644 --- a/tests/unit/plugins/modules/test_nios_host_record.py +++ b/tests/unit/plugins/modules/test_nios_host_record.py @@ -41,7 +41,7 @@ def setUp(self): self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -77,7 +77,7 @@ def test_nios_host_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__()}) + wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible'}) def test_nios_host_record_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible', diff --git a/tests/unit/plugins/modules/test_nios_mx_record.py b/tests/unit/plugins/modules/test_nios_mx_record.py index 5b3eeb77..55524b4d 100644 --- a/tests/unit/plugins/modules/test_nios_mx_record.py +++ b/tests/unit/plugins/modules/test_nios_mx_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_mx_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -80,7 +80,7 @@ def test_nios_mx_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible.com', 'mx': 'mailhost.ansible.com', 'preference': 0}) def test_nios_mx_record_update_comment(self): diff --git a/tests/unit/plugins/modules/test_nios_naptr_record.py b/tests/unit/plugins/modules/test_nios_naptr_record.py index 10469bdf..44c9c349 100644 --- a/tests/unit/plugins/modules/test_nios_naptr_record.py +++ b/tests/unit/plugins/modules/test_nios_naptr_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_naptr_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -82,7 +82,7 @@ def test_nios_naptr_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': '*.subscriber-100.ansiblezone.com', 'order': '1000', 'preference': '10', 'replacement': 'replacement1.network.ansiblezone.com'}) diff --git a/tests/unit/plugins/modules/test_nios_network_view.py b/tests/unit/plugins/modules/test_nios_network_view.py index 4d0f0a3d..fc95f180 100644 --- a/tests/unit/plugins/modules/test_nios_network_view.py +++ b/tests/unit/plugins/modules/test_nios_network_view.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_network_view.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -78,7 +78,7 @@ def test_nios_network_view_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__()}) + wapi.create_object.assert_called_once_with('testobject', {'name': 'ansible'}) def test_nios_network_view_update_comment(self): self.module.params = {'provider': None, 'state': 'present', 'name': 'default', diff --git a/tests/unit/plugins/modules/test_nios_nsgroup.py b/tests/unit/plugins/modules/test_nios_nsgroup.py index 315e3ba8..60b21dcc 100644 --- a/tests/unit/plugins/modules/test_nios_nsgroup.py +++ b/tests/unit/plugins/modules/test_nios_nsgroup.py @@ -42,7 +42,7 @@ def setUp(self): self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -77,7 +77,7 @@ def test_nios_nsgroup_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__()}) + wapi.create_object.assert_called_once_with('testobject', {'name': 'my-simple-group'}) def test_nios_nsgroup_remove(self): self.module.params = {'provider': None, 'state': 'absent', 'name': 'my-simple-group', diff --git a/tests/unit/plugins/modules/test_nios_srv_record.py b/tests/unit/plugins/modules/test_nios_srv_record.py index 5d36d4cc..9a6f3fb3 100644 --- a/tests/unit/plugins/modules/test_nios_srv_record.py +++ b/tests/unit/plugins/modules/test_nios_srv_record.py @@ -40,7 +40,7 @@ def setUp(self): self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_srv_record.WapiModule.run') self.mock_wapi_run.start() self.load_config = self.mock_wapi_run.start() - self.mock_check_type_dict = patch('ansible_collections.infoblox.nios_modules.plugins.module_utils.api.check_type_dict') + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') self.mock_check_type_dict_obj = self.mock_check_type_dict.start() def tearDown(self): @@ -83,7 +83,7 @@ def test_nios_srv_record_create(self): res = wapi.run('testobject', test_spec) self.assertTrue(res['changed']) - wapi.create_object.assert_called_once_with('testobject', {'name': self.mock_check_type_dict_obj().__getitem__(), + wapi.create_object.assert_called_once_with('testobject', {'name': '_sip._tcp.service.ansible.com', 'port': 5080, 'target': 'service1.ansible.com', 'priority': 10, 'weight': 10}) def test_nios_srv_record_update_comment(self): diff --git a/tests/unit/plugins/modules/utils.py b/tests/unit/plugins/modules/utils.py index 6a00fd25..15e7ec14 100644 --- a/tests/unit/plugins/modules/utils.py +++ b/tests/unit/plugins/modules/utils.py @@ -4,8 +4,10 @@ __metaclass__ = type import json - -from ansible_collections.community.general.tests.unit.compat import unittest +try: + from ansible_collections.community.general.tests.unit.compat import unittest +except ImportError: + import unittest from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils.common.text.converters import to_bytes diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt index 0e1091bc..fc67ca9e 100644 --- a/tests/unit/requirements.txt +++ b/tests/unit/requirements.txt @@ -1,7 +1,9 @@ infoblox-client pytest +pytest-forked pytest-xdist mock pytest-mock pytest-cov -coverage==4.5.4 +coverage==7.3.2 +