Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/1182-fix-contact-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- Change `netbox_contact.contact_group` to `contact_groups`
- Add integration tests for contact groups
4 changes: 2 additions & 2 deletions plugins/module_utils/netbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
cluster_type="slug",
config_context="name",
config_template="name",
contact_group="name",
contact_groups="name",
contact_role="name",
custom_field="name",
choice_set="name",
Expand Down Expand Up @@ -643,7 +643,7 @@
"cluster_type": "type",
"cluster_group": "group",
"component": "component_id",
"contact_group": "group",
"contact_groups": "groups",
"device_role": "role",
"fhrp_group": "group",
"inventory_item_role": "role",
Expand Down
12 changes: 8 additions & 4 deletions plugins/modules/netbox_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@
- Comments on the contact
required: false
type: str
contact_group:
contact_groups:
description:
- Group assignment for the contact
- Groups that the contact belongs to
required: false
type: raw
type: list
elements: raw
link:
description:
- URL associated with the contact
Expand Down Expand Up @@ -121,6 +122,9 @@
title: Mr Contact
phone: 123456789
email: [email protected]
contact_groups:
- Group 1
- Group 2
tags:
- tagA
- tagB
Expand Down Expand Up @@ -168,7 +172,7 @@ def main():
address=dict(required=False, type="str"),
description=dict(required=False, type="str"),
comments=dict(required=False, type="str"),
contact_group=dict(required=False, type="raw"),
contact_groups=dict(required=False, type="list", elements="raw"),
link=dict(required=False, type="str"),
tags=dict(required=False, type="list", elements="raw"),
custom_fields=dict(required=False, type="dict"),
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/targets/v4.3/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
tags:
- netbox_contact

- name: NETBOX_CONTACT_GROUP TESTS
ansible.builtin.include_tasks:
file: netbox_contact_group.yml
apply:
tags:
- netbox_contact_group
tags:
- netbox_contact_group

- name: NETBOX_CONTACT_ROLE TESTS
ansible.builtin.include_tasks:
file: netbox_contact_role.yml
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/targets/v4.3/tasks/netbox_contact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,31 @@
- test_five['contact']['phone'] == "12345678"
- test_five['contact']['tags'] | length == 3
- test_five['msg'] == "contact Contact ABC created"

- name: 6 Setup - Create contact group
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group With Contacts
register: test_group

- name: 6 - Create contact with contact group
netbox.netbox.netbox_contact:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Grouped Contact 1
contact_groups:
- Contact Group With Contacts
register: test_six

- name: 6 - ASSERT
ansible.builtin.assert:
that:
- test_six is changed
- test_six['diff']['before']['state'] == "absent"
- test_six['diff']['after']['state'] == "present"
- test_six['contact']['name'] == "Grouped Contact 1"
- test_six['contact']['groups'] == [test_group['contact_group']['id']]
- test_six['msg'] == "contact Grouped Contact 1 created"
119 changes: 119 additions & 0 deletions tests/integration/targets/v4.3/tasks/netbox_contact_group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
##
##
### NETBOX_CONTACT_GROUP
##
##
- name: 1 - Test contact group creation
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group 1
register: test_one

- name: 1 - ASSERT
ansible.builtin.assert:
that:
- test_one is changed
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['contact_group']['name'] == "Contact Group 1"
- test_one['msg'] == "contact_group Contact Group 1 created"

- name: Test duplicate contact group
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group 1
register: test_two

- name: 2 - ASSERT
ansible.builtin.assert:
that:
- not test_two['changed']
- test_two['contact_group']['name'] == "Contact Group 1"
- test_two['msg'] == "contact_group Contact Group 1 already exists"

- name: 3 - Test update
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group 1
description: The first contact group
register: test_three

- name: 3 - ASSERT
ansible.builtin.assert:
that:
- test_three is changed
- test_three['diff']['after']['description'] == "The first contact group"
- test_three['contact_group']['name'] == "Contact Group 1"
- test_three['contact_group']['description'] == "The first contact group"
- test_three['msg'] == "contact_group Contact Group 1 updated"

- name: 4 - Test delete
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group 1
state: absent
register: test_four

- name: 4 - ASSERT
ansible.builtin.assert:
that:
- test_four is changed
- test_four['diff']['before']['state'] == "present"
- test_four['diff']['after']['state'] == "absent"
- test_four['msg'] == "contact_group Contact Group 1 deleted"

- name: 5 - Create contact group with all parameters
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group Parent
slug: the-parent-contact-group
description: The parent contact group
tags:
- tagA
- tagB
- tagC
state: present
register: test_five

- name: 5 - ASSERT
ansible.builtin.assert:
that:
- test_five is changed
- test_five['diff']['before']['state'] == "absent"
- test_five['diff']['after']['state'] == "present"
- test_five['contact_group']['name'] == "Contact Group Parent"
- test_five['contact_group']['slug'] == "the-parent-contact-group"
- test_five['contact_group']['description'] == "The parent contact group"
- test_five['contact_group']['tags'] | length == 3
- test_five['msg'] == "contact_group Contact Group Parent created"

- name: 6 - Create contact group with parent contact group
netbox.netbox.netbox_contact_group:
netbox_url: http://localhost:32768
netbox_token: "0123456789abcdef0123456789abcdef01234567"
data:
name: Contact Group Child
parent_contact_group: Contact Group Parent
state: present
register: test_six

- name: 6 - ASSERT
ansible.builtin.assert:
that:
- test_six is changed
- test_six['diff']['before']['state'] == "absent"
- test_six['diff']['after']['state'] == "present"
- test_six['contact_group']['name'] == "Contact Group Child"
- test_six['contact_group']['parent'] == test_five['contact_group']['id']
- test_six['msg'] == "contact_group Contact Group Child created"
Loading