phpipam-ansible-modules icon indicating copy to clipboard operation
phpipam-ansible-modules copied to clipboard

add location_id

Open urskog84 opened this issue 1 year ago • 1 comments

lmost every object in the phpIPAM database have the option to set a "location" that's correspond to the ID of the location.

would be nice to have that available int the modules.

address device subnet

Example

- name: "Create device"
  codeaffen.phpipam.device:
    username: "admin"
    password: "s3cr3t"
    server_url: "https://ipam.example.com"
    hostname: "leaf-example-01"
    ipaddress: "192.0.2.222"
    location_id: 53          <--- New
    sections:
      - Example Inc.
      - DEVOPS department
    state: present

urskog84 avatar Jan 06 '25 08:01 urskog84

@urskog84 thank you for rephrasing your feature request. We accept it, but we can't promise to implement it soon. So we also label it with help wanted.

Regarding the implementation, we prefer location as an extra field in the mentioned entity types. The module resolves the name to an ID, which will used to save it to the entity accordingly.

- name: "Create device"
  codeaffen.phpipam.device:
    username: "admin"
    password: "s3cr3t"
    server_url: "https://ipam.example.com"
    hostname: "leaf-example-01"
    ipaddress: "192.0.2.222"
    location: 'my location'          <--- New
    sections:
      - Example Inc.
      - DEVOPS department
    state: present

For anyone who is keen to implement this feature, the logic for resolving names to its IDs exists for various keys.

cmeissner avatar Jan 08 '25 19:01 cmeissner

Regarding the implementation, we prefer location as an extra field in the mentioned entity types. The module resolves the name to an ID, which will used to save it to the entity accordingly.

For anyone who is keen to implement this feature, the logic for resolving names to its IDs exists for various keys.

The logic for resolving a location name to the related ID is already there:

https://github.com/codeaffen/phpipam-ansible-modules/blob/340c0f9b6f695b22b0152c473f3bab97d83bbea5/plugins/modules/subnet.py#L226

The task now is to:

  1. identify the modules which support location
  2. add the line location=dict(type='entity', controller='tools/locations'), to each phpipam_spec dict of each identified module
  3. add the following code to the options dict DOCUMENTATION section of each identified module
    
    location:
        description: Subnet location
        type: str
        required: false
    
  4. ideally the existing tests be updated
  5. a changelog fragment is placed in changelogs/fragments describing the change

Hope this will help to have this feature soon for all supported modules.

cmeissner avatar Jun 24 '25 15:06 cmeissner