diff --git a/meta/runtime.yml b/meta/runtime.yml index 1c3faae8c..5c69ef1db 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -50,6 +50,8 @@ action_groups: - netbox_l2vpn_termination - netbox_location - netbox_manufacturer + - netbox_module + - netbox_module_bay - netbox_module_type - netbox_platform - netbox_power_feed diff --git a/plugins/module_utils/netbox_dcim.py b/plugins/module_utils/netbox_dcim.py index 2482c90cf..b9d5edc12 100644 --- a/plugins/module_utils/netbox_dcim.py +++ b/plugins/module_utils/netbox_dcim.py @@ -32,6 +32,8 @@ NB_INVENTORY_ITEM_ROLES = "inventory_item_roles" NB_LOCATIONS = "locations" NB_MANUFACTURERS = "manufacturers" +NB_MODULES = "modules" +NB_MODULE_BAYS = "module_bays" NB_MODULE_TYPES = "module_types" NB_PLATFORMS = "platforms" NB_POWER_FEEDS = "power_feeds" @@ -91,6 +93,9 @@ def run(self): - inventory_item_roles - locations - manufacturers + - modules + - module_bays + - module_types - platforms - power_feeds - power_outlets @@ -150,6 +155,38 @@ def run(self): data.get("termination_b_type"), termination_b_name, ) + elif endpoint_name == "module": + if isinstance( + self.module.params["data"]["device"], dict + ) and self.module.params["data"]["device"].get("name"): + device_name = self.module.params["data"]["device"]["name"] + elif isinstance( + self.module.params["data"]["device"], dict + ) and self.module.params["data"]["device"].get("slug"): + device_name = self.module.params["data"]["device"]["slug"] + else: + device_name = self.module.params["data"]["device"] + if isinstance( + self.module.params["data"]["module_bay"], dict + ) and self.module.params["data"]["module_bay"].get("name"): + module_bay = self.module.params["data"]["module_bay"]["name"] + elif isinstance( + self.module.params["data"]["module_bay"], dict + ) and self.module.params["data"]["module_bay"].get("slug"): + module_bay = self.module.params["data"]["module_bay"]["slug"] + else: + module_bay = self.module.params["data"]["module_bay"] + if isinstance( + self.module.params["data"]["module_type"], dict + ) and self.module.params["data"]["module_bay"].get("model"): + module_type = self.module.params["data"]["module_type"]["model"] + elif isinstance( + self.module.params["data"]["module_type"], dict + ) and self.module.params["data"]["module_bay"].get("part_number"): + module_type = self.module.params["data"]["module_type"]["part_number"] + else: + module_type = self.module.params["data"]["module_type"] + name = "%s: %s (%s)" % (device_name, module_bay, module_type) if self.endpoint in SLUG_REQUIRED: if not data.get("slug"): diff --git a/plugins/module_utils/netbox_utils.py b/plugins/module_utils/netbox_utils.py index 04c327ff8..33f1feadb 100644 --- a/plugins/module_utils/netbox_utils.py +++ b/plugins/module_utils/netbox_utils.py @@ -58,6 +58,8 @@ "inventory_item_roles": {}, "locations": {}, "manufacturers": {}, + "modules": {}, + "module_bays": {}, "module_types": {}, "platforms": {}, "power_feeds": {}, @@ -161,6 +163,8 @@ l2vpn_termination="id", location="slug", manufacturer="slug", + modules="id", + module_bays="name", module_type="model", nat_inside="address", nat_outside="address", @@ -254,6 +258,8 @@ "lag": "interfaces", "manufacturer": "manufacturers", "master": "devices", + "module": "modules", + "module_bay": "module_bays", "module_type": "module_types", "nat_inside": "ip_addresses", "nat_outside": "ip_addresses", @@ -359,6 +365,8 @@ "l2vpn_terminations": "l2vpn_termination", "locations": "location", "manufacturers": "manufacturer", + "modules": "module", + "module_bays": "module_bay", "module_types": "module_type", "platforms": "platform", "power_feeds": "power_feed", @@ -477,6 +485,8 @@ ), "lag": set(["name"]), "location": set(["name", "slug", "site"]), + "module": set(["device", "module_bay", "module_type"]), + "module_bay": set(["name"]), "module_type": set(["model"]), "manufacturer": set(["slug"]), "master": set(["name"]), @@ -1072,6 +1082,13 @@ def _build_query_params( query_key: module_data.get("assigned_object_id"), } ) + elif parent == "module": + query_dict.update( + { + "module_bay_id": query_dict.pop("module_bay"), + "module_type_id": query_dict.pop("module_type"), + } + ) elif "_template" in parent: if query_dict.get("device_type"): query_dict["devicetype_id"] = query_dict.pop("device_type") diff --git a/plugins/modules/netbox_module.py b/plugins/modules/netbox_module.py new file mode 100644 index 000000000..d70828046 --- /dev/null +++ b/plugins/modules/netbox_module.py @@ -0,0 +1,213 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2022, Erwan TONNERRE (@etonnerre) +# 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 = r""" +--- +module: netbox_module +short_description: Create, update or delete module within NetBox +description: + - Creates, updates or removes module from NetBox +notes: + - Tags should be defined as a YAML list + - This should be ran with connection C(local) and hosts C(localhost) +author: + - Erwan TONNERRE (@etonnerre) +requirements: + - pynetbox +version_added: '3.17.0' +extends_documentation_fragment: + - netbox.netbox.common +options: + data: + description: + - Defines the device type configuration + suboptions: + device: + description: + - The device of the module + required: True + type: raw + module_bay: + description: + - The module bay of the module + required: true + type: raw + module_type: + description: + - The module type of the module + required: true + type: raw + status: + description: + - The status of the module + choices: + - offline + - active + - planned + - staged + - side-to-rear + - failed + - decommissioning + required: false + type: str + serial: + description: + - The weight of the device type + required: false + type: str + description: + description: + - The description of the module + required: false + type: str + asset_tag: + description: + - The asset tag of the modyle + required: false + type: str + comments: + description: + - Comments that may include additional information in regards to the module + required: false + type: str + tags: + description: + - Any tags that the module may need to be associated with + required: false + type: list + elements: raw + custom_fields: + description: + - must exist in NetBox + required: false + type: dict + required: true + type: dict +""" + +EXAMPLES = r""" +- name: "Test NetBox modules" + connection: local + hosts: localhost + gather_facts: False + + tasks: + - name: Create module type within NetBox with only required information + netbox.netbox.netbox_module: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + + - name: Create module type within NetBox + netbox.netbox.netbox_module: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + device: + name: C9300-DEMO + site: EUPARIS + module_bay: + name: Network Module + position: 1 + module_type: + manufacturer: Cisco + model: C9300-NM-8X + state: present + + - name: Delete module type within netbox + netbox.netbox.netbox_module: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + asset_tag: 00001 + serial: XXXNNNNXXXX + state: absent +""" + +RETURN = r""" +module: + description: Serialized object as created or already existent within NetBox + returned: success (when I(state=present)) + type: dict +msg: + description: Message indicating failure or info about what has been achieved + returned: always + type: str +""" + +from ansible_collections.netbox.netbox.plugins.module_utils.netbox_utils import ( + NetboxAnsibleModule, + NETBOX_ARG_SPEC, +) +from ansible_collections.netbox.netbox.plugins.module_utils.netbox_dcim import ( + NetboxDcimModule, + NB_MODULES, +) +from copy import deepcopy + + +def main(): + """ + Main entry point for module execution + """ + argument_spec = deepcopy(NETBOX_ARG_SPEC) + argument_spec.update( + dict( + data=dict( + type="dict", + required=True, + options=dict( + device=dict(required=True, type="raw"), + module_bay=dict(required=True, type="raw"), + module_type=dict(required=True, type="raw"), + status=dict( + required=False, + type="str", + choices=[ + "offline", + "active", + "planned", + "staged", + "side-to-rear", + "failed", + "decommissioning", + ], + ), + serial=dict(required=False, type="str"), + description=dict(required=False, type="str"), + asset_tag=dict(required=False, type="str"), + comments=dict(required=False, type="str"), + tags=dict(required=False, type="list", elements="raw"), + custom_fields=dict(required=False, type="dict"), + ), + ), + ) + ) + required_if = [ + ("state", "present", ["device", "module_bay", "module_type", "status"]), + ("state", "absent", ["device", "module_bay", "module_type"]), + ] + + module = NetboxAnsibleModule( + argument_spec=argument_spec, supports_check_mode=True, required_if=required_if + ) + + netbox_device_type = NetboxDcimModule(module, NB_MODULES) + netbox_device_type.run() + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/plugins/modules/netbox_module_bay.py b/plugins/modules/netbox_module_bay.py new file mode 100644 index 000000000..fa7050d68 --- /dev/null +++ b/plugins/modules/netbox_module_bay.py @@ -0,0 +1,156 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2023, Erwan TONNERRE (@etonnerre) +# 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 = r""" +--- +module: netbox_module_bay +short_description: Create, update or delete module bay within NetBox +description: + - Creates, updates or removes module bay from NetBox +notes: + - Tags should be defined as a YAML list + - This should be ran with connection C(local) and hosts C(localhost) +author: + - Erwan TONNERRE (@etonnerre) +requirements: + - pynetbox +version_added: '3.17.0' +extends_documentation_fragment: + - netbox.netbox.common +options: + data: + description: + - Defines the module bay configuration + suboptions: + device: + description: + - The device of the module bay + required: true + type: raw + name: + description: + - The model of the module bay + required: true + type: raw + label: + description: + - The label of the module bay + required: false + type: str + position: + description: + - The position of the module bay + required: true + type: str + description: + description: + - The description of the module bay + required: false + type: str + tags: + description: + - Any tags that the module bay may need to be associated with + required: false + type: list + elements: raw + custom_fields: + description: + - must exist in NetBox + required: false + type: dict + required: true + type: dict +""" + +EXAMPLES = r""" +- name: "Test NetBox modules" + connection: local + hosts: localhost + gather_facts: False + + tasks: + - name: Create module bay within NetBox with only required information + netbox.netbox.netbox_module_bay: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + device: C9300-DEMO + name: C9300-DEMO-SLOT-0 + position: 0 + state: present + + - name: Delete module bay within netbox + netbox.netbox.netbox_module_bay: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + name: C9300-DEMO-SLOT-0 + state: absent +""" + +RETURN = r""" +module_bay: + description: Serialized object as created or already existent within NetBox + returned: success (when I(state=present)) + type: dict +msg: + description: Message indicating failure or info about what has been achieved + returned: always + type: str +""" + +from ansible_collections.netbox.netbox.plugins.module_utils.netbox_utils import ( + NetboxAnsibleModule, + NETBOX_ARG_SPEC, +) +from ansible_collections.netbox.netbox.plugins.module_utils.netbox_dcim import ( + NetboxDcimModule, + NB_MODULE_BAYS, +) +from copy import deepcopy + + +def main(): + """ + Main entry point for module execution + """ + argument_spec = deepcopy(NETBOX_ARG_SPEC) + argument_spec.update( + dict( + data=dict( + type="dict", + required=True, + options=dict( + device=dict(required=True, type="raw"), + name=dict(required=True, type="raw"), + label=dict(required=False, type="str"), + position=dict(required=True, type="str"), + description=dict(required=False, type="str"), + tags=dict(required=False, type="list", elements="raw"), + custom_fields=dict(required=False, type="dict"), + ), + ), + ) + ) + + required_if = [ + ("state", "present", ["device", "name", "position"]), + ("state", "absent", ["name"]), + ] + + module = NetboxAnsibleModule( + argument_spec=argument_spec, supports_check_mode=True, required_if=required_if + ) + + netbox_module_bay = NetboxDcimModule(module, NB_MODULE_BAYS) + netbox_module_bay.run() + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/tests/integration/targets/v3.5/tasks/netbox_module.yml b/tests/integration/targets/v3.5/tasks/netbox_module.yml new file mode 100644 index 000000000..e8f090d8c --- /dev/null +++ b/tests/integration/targets/v3.5/tasks/netbox_module.yml @@ -0,0 +1,107 @@ +--- +## +## +### NETBOX_MODULE +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_one + +- name: "MODULE 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module']['device'] == "C9300-DEMO" + - test_one['module']['module_bay'] == "Network Module" + - test_one['module']['module_type'] == "C9300-NM-8X" + - test_one['msg'] == "module ws-test-3750 created" + +- name: "MODULE 2: Create duplicate" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_two + +- name: "MODULE 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module']['device'] == "C9300-DEMO" + - test_two['module']['module_bay'] == "Network Module" + - test_two['module']['module_type'] == "C9300-NM-8X" + - test_two['msg'] == "module C9300-NM-8X already exists in slot Network Module of C9300-DEMO" + +- name: "MODULE 3: ASSERT - Update" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + serial: XXXNNNNXXXX + state: present + register: test_three + +- name: "MODULE 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['serial'] == "XXXNNNNXXXX" + - test_three['module']['device'] == "C9300-DEMO" + - test_three['module']['module_bay'] == "Network Module" + - test_three['module']['module_type'] == "C9300-NM-8X" + - test_three['module']['serial'] == "XXXNNNNXXXX" + - test_three['msg'] == "module C9300-DEMO - Network Module - C9300-NM-8X updated" + +- name: "MODULE 4: ASSERT - Delete" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: absent + register: test_four + +- name: "MODULE 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module C9300-NM-8X deleted in slot Network Module of C9300-DEMO" + +- name: "MODULE 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-2Y + state: absent + register: test_five + +- name: "MODULE 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module'] == None + - test_five['msg'] == "module Test Module Type already absent" diff --git a/tests/integration/targets/v3.5/tasks/netbox_module_bay.yml b/tests/integration/targets/v3.5/tasks/netbox_module_bay.yml new file mode 100644 index 000000000..44bb76269 --- /dev/null +++ b/tests/integration/targets/v3.5/tasks/netbox_module_bay.yml @@ -0,0 +1,105 @@ +--- +## +## +### NETBOX_MODULE_BAY +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_one + +- name: "MODULE BAY 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module_bay']['device'] == "C9300-DEMO" + - test_one['module_bay']['name'] == "Network Module" + - test_one['module_bay']['position'] == "0" + - test_one['msg'] == "module_bay Network Module in C9300-DEMO position 0 created" + +- name: "MODULE BAY 2: Create duplicate" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_two + +- name: "MODULE BAY 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module_bay']['device'] == "C9300-DEMO" + - test_two['module_bay']['name'] == "Network Module" + - test_two['module_bay']['position'] == "0" + - test_two['msg'] == "module_bay Network Module in C9300-DEMO position 0 already exists" + +- name: "MODULE BAY 3: ASSERT - Update" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + label: TEST + state: present + register: test_three + +- name: "MODULE BAY 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['label'] == "TEST" + - test_three['module_bay']['device'] == "C9300-DEMO" + - test_three['module_bay']['name'] == "Network Module" + - test_three['module_bay']['position'] == "0" + - test_three['module_bay']['label'] == "TEST" + - test_three['msg'] == "module_bay Network Module in C9300-DEMO position 0 updated with label TEST" + +- name: "MODULE BAY 4: ASSERT - Delete" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_four + +- name: "MODULE BAY 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module_bay Network Module in C9300-DEMO position 0 deleted" + +- name: "MODULE BAY 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_five + +- name: "MODULE BAY 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module_bay'] == None + - test_five['msg'] == "module_bay Network Module already absent" diff --git a/tests/integration/targets/v3.6/tasks/netbox_module.yml b/tests/integration/targets/v3.6/tasks/netbox_module.yml new file mode 100644 index 000000000..e8f090d8c --- /dev/null +++ b/tests/integration/targets/v3.6/tasks/netbox_module.yml @@ -0,0 +1,107 @@ +--- +## +## +### NETBOX_MODULE +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_one + +- name: "MODULE 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module']['device'] == "C9300-DEMO" + - test_one['module']['module_bay'] == "Network Module" + - test_one['module']['module_type'] == "C9300-NM-8X" + - test_one['msg'] == "module ws-test-3750 created" + +- name: "MODULE 2: Create duplicate" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_two + +- name: "MODULE 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module']['device'] == "C9300-DEMO" + - test_two['module']['module_bay'] == "Network Module" + - test_two['module']['module_type'] == "C9300-NM-8X" + - test_two['msg'] == "module C9300-NM-8X already exists in slot Network Module of C9300-DEMO" + +- name: "MODULE 3: ASSERT - Update" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + serial: XXXNNNNXXXX + state: present + register: test_three + +- name: "MODULE 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['serial'] == "XXXNNNNXXXX" + - test_three['module']['device'] == "C9300-DEMO" + - test_three['module']['module_bay'] == "Network Module" + - test_three['module']['module_type'] == "C9300-NM-8X" + - test_three['module']['serial'] == "XXXNNNNXXXX" + - test_three['msg'] == "module C9300-DEMO - Network Module - C9300-NM-8X updated" + +- name: "MODULE 4: ASSERT - Delete" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: absent + register: test_four + +- name: "MODULE 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module C9300-NM-8X deleted in slot Network Module of C9300-DEMO" + +- name: "MODULE 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-2Y + state: absent + register: test_five + +- name: "MODULE 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module'] == None + - test_five['msg'] == "module Test Module Type already absent" diff --git a/tests/integration/targets/v3.6/tasks/netbox_module_bay.yml b/tests/integration/targets/v3.6/tasks/netbox_module_bay.yml new file mode 100644 index 000000000..44bb76269 --- /dev/null +++ b/tests/integration/targets/v3.6/tasks/netbox_module_bay.yml @@ -0,0 +1,105 @@ +--- +## +## +### NETBOX_MODULE_BAY +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_one + +- name: "MODULE BAY 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module_bay']['device'] == "C9300-DEMO" + - test_one['module_bay']['name'] == "Network Module" + - test_one['module_bay']['position'] == "0" + - test_one['msg'] == "module_bay Network Module in C9300-DEMO position 0 created" + +- name: "MODULE BAY 2: Create duplicate" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_two + +- name: "MODULE BAY 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module_bay']['device'] == "C9300-DEMO" + - test_two['module_bay']['name'] == "Network Module" + - test_two['module_bay']['position'] == "0" + - test_two['msg'] == "module_bay Network Module in C9300-DEMO position 0 already exists" + +- name: "MODULE BAY 3: ASSERT - Update" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + label: TEST + state: present + register: test_three + +- name: "MODULE BAY 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['label'] == "TEST" + - test_three['module_bay']['device'] == "C9300-DEMO" + - test_three['module_bay']['name'] == "Network Module" + - test_three['module_bay']['position'] == "0" + - test_three['module_bay']['label'] == "TEST" + - test_three['msg'] == "module_bay Network Module in C9300-DEMO position 0 updated with label TEST" + +- name: "MODULE BAY 4: ASSERT - Delete" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_four + +- name: "MODULE BAY 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module_bay Network Module in C9300-DEMO position 0 deleted" + +- name: "MODULE BAY 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_five + +- name: "MODULE BAY 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module_bay'] == None + - test_five['msg'] == "module_bay Network Module already absent" diff --git a/tests/integration/targets/v3.7/tasks/netbox_module.yml b/tests/integration/targets/v3.7/tasks/netbox_module.yml new file mode 100644 index 000000000..e8f090d8c --- /dev/null +++ b/tests/integration/targets/v3.7/tasks/netbox_module.yml @@ -0,0 +1,107 @@ +--- +## +## +### NETBOX_MODULE +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_one + +- name: "MODULE 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module']['device'] == "C9300-DEMO" + - test_one['module']['module_bay'] == "Network Module" + - test_one['module']['module_type'] == "C9300-NM-8X" + - test_one['msg'] == "module ws-test-3750 created" + +- name: "MODULE 2: Create duplicate" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: present + register: test_two + +- name: "MODULE 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module']['device'] == "C9300-DEMO" + - test_two['module']['module_bay'] == "Network Module" + - test_two['module']['module_type'] == "C9300-NM-8X" + - test_two['msg'] == "module C9300-NM-8X already exists in slot Network Module of C9300-DEMO" + +- name: "MODULE 3: ASSERT - Update" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + serial: XXXNNNNXXXX + state: present + register: test_three + +- name: "MODULE 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['serial'] == "XXXNNNNXXXX" + - test_three['module']['device'] == "C9300-DEMO" + - test_three['module']['module_bay'] == "Network Module" + - test_three['module']['module_type'] == "C9300-NM-8X" + - test_three['module']['serial'] == "XXXNNNNXXXX" + - test_three['msg'] == "module C9300-DEMO - Network Module - C9300-NM-8X updated" + +- name: "MODULE 4: ASSERT - Delete" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-8X + state: absent + register: test_four + +- name: "MODULE 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module C9300-NM-8X deleted in slot Network Module of C9300-DEMO" + +- name: "MODULE 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + module_bay: Network Module + module_type: C9300-NM-2Y + state: absent + register: test_five + +- name: "MODULE 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module'] == None + - test_five['msg'] == "module Test Module Type already absent" diff --git a/tests/integration/targets/v3.7/tasks/netbox_module_bay.yml b/tests/integration/targets/v3.7/tasks/netbox_module_bay.yml new file mode 100644 index 000000000..44bb76269 --- /dev/null +++ b/tests/integration/targets/v3.7/tasks/netbox_module_bay.yml @@ -0,0 +1,105 @@ +--- +## +## +### NETBOX_MODULE_BAY +## +## +- name: "MODULE 1: Necessary info creation" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_one + +- name: "MODULE BAY 1: ASSERT - Necessary info creation" + assert: + that: + - test_one is changed + - test_one['diff']['before']['state'] == "absent" + - test_one['diff']['after']['state'] == "present" + - test_one['module_bay']['device'] == "C9300-DEMO" + - test_one['module_bay']['name'] == "Network Module" + - test_one['module_bay']['position'] == "0" + - test_one['msg'] == "module_bay Network Module in C9300-DEMO position 0 created" + +- name: "MODULE BAY 2: Create duplicate" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + state: present + register: test_two + +- name: "MODULE BAY 2: ASSERT - Create duplicate" + assert: + that: + - not test_two['changed'] + - test_two['module_bay']['device'] == "C9300-DEMO" + - test_two['module_bay']['name'] == "Network Module" + - test_two['module_bay']['position'] == "0" + - test_two['msg'] == "module_bay Network Module in C9300-DEMO position 0 already exists" + +- name: "MODULE BAY 3: ASSERT - Update" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + position: 0 + label: TEST + state: present + register: test_three + +- name: "MODULE BAY 3: ASSERT - Update" + assert: + that: + - test_three is changed + - test_three['diff']['after']['label'] == "TEST" + - test_three['module_bay']['device'] == "C9300-DEMO" + - test_three['module_bay']['name'] == "Network Module" + - test_three['module_bay']['position'] == "0" + - test_three['module_bay']['label'] == "TEST" + - test_three['msg'] == "module_bay Network Module in C9300-DEMO position 0 updated with label TEST" + +- name: "MODULE BAY 4: ASSERT - Delete" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_four + +- name: "MODULE BAY 4: ASSERT - Delete" + assert: + that: + - test_four is changed + - test_four['diff']['before']['state'] == "present" + - test_four['diff']['after']['state'] == "absent" + - test_four['msg'] == "module_bay Network Module in C9300-DEMO position 0 deleted" + +- name: "MODULE BAY 5: ASSERT - Delete non existing" + netbox.netbox.netbox_module_bay: + netbox_url: http://localhost:32768 + netbox_token: 0123456789abcdef0123456789abcdef01234567 + data: + device: C9300-DEMO + name: Network Module + state: absent + register: test_five + +- name: "MODULE BAY 5: ASSERT - Delete non existing`" + assert: + that: + - not test_five['changed'] + - test_five['module_bay'] == None + - test_five['msg'] == "module_bay Network Module already absent"