Skip to content

Fix resolving devices by defining the correct search key #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2025
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test-setup: | tests/test_playbooks/vars/server.yml install-deps install
test -f tests/test_playbooks/vars/server.yml

test-all:
coverage run -m pytest -n 4 --forked -vv 'tests/test_crud.py::test_crud'
coverage run -m pytest -n 8 --forked -vv 'tests/test_crud.py::test_crud'

test-%:
coverage run -m pytest --forked -vv 'tests/test_crud.py::test_case_crud' --testcase $*
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/fix_device_resolution_in_modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- fix resolution of device in address module - \#135
2 changes: 2 additions & 0 deletions plugins/module_utils/phpipam_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def _resolve_entity(self, key): # noqa: C901
result = self.find_device_type(self.phpipam_params[key])
elif controller == 'tools/tags':
result = self.find_by_key(controller=controller, value=self.phpipam_params[key], key='type')
elif controller == 'tools/devices':
result = self.find_by_key(controller=controller, value=self.phpipam_params[key], key='hostname')
elif controller == 'vlan':
result = self.find_vlan(self.phpipam_params[key], self.phpipam_params['routing_domain'])
elif controller == 'vrf':
Expand Down
53 changes: 53 additions & 0 deletions tests/test_playbooks/address_device_mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
- name: Address and device module test
hosts: localhost
gather_facts: false
vars_files:
- vars/server.yml
- vars/address.yml
- vars/device.yml
vars:
address_device:
device: 'Test device'
address: '{{ base_address_data | combine(address_device) }}'
tasks:
- name: Create entities
tags: [create]
block:
- name: Create device
ansible.builtin.include_tasks: tasks/device.yml
vars:
step: create device
device: '{{ base_device_data }}'
- name: Create address
ansible.builtin.include_tasks: tasks/address.yml
vars:
step: create address
- name: Create entities again, no change
tags: [read]
block:
- name: Create device again, no change
ansible.builtin.include_tasks: tasks/device.yml
vars:
step: create device again, no change
device: '{{ base_device_data }}'
- name: Create address again, no change
ansible.builtin.include_tasks: tasks/address.yml
vars:
step: create address again, no change
- name: Delete entities
tags: [delete]
block:
- name: Delete device
ansible.builtin.include_tasks: tasks/device.yml
vars:
step: delete device
override:
state: absent
device: '{{ base_device_data | combine(override) }}'
- name: Delete address
ansible.builtin.include_tasks: tasks/address.yml
vars:
step: delete address
override:
state: absent
address: '{{ base_address_data | combine(override) }}'
Loading