ansible-collections / azure

Development area for Azure Collections
https://galaxy.ansible.com/azure/azcollection
GNU General Public License v3.0
245 stars 327 forks source link

azure_rm_iotdevice - add parent device flag #1024

Open vasdee opened 1 year ago

vasdee commented 1 year ago
SUMMARY

When creating an iot device in iothub via azure_rm_iotdevice, there is currently no way to specify the parent device (which has been a feature since 1.2 of iotedge/hub)

Currently we need to fall back to the CLI to get this functionality

- name: Set the parent device
  command:
    cmd: az iot hub device-identity parent set -d "{{ iot_edge_device_id }}" --pd "{{ iot_edge_parent_device_id }}" -n "{{ iot_azure_iothub_name }}" --force
  when: iot_edge_parent_device_id is defined

Having the parent information available in azure_rm_iotdevice_info would be very handy as well.

ISSUE TYPE
COMPONENT NAME

azure_rm_iotdevice - ability to specify the parent azure_rm_iotdevice_info - ability to retrieve the parent device

ADDITIONAL INFORMATION

It would remove the need to fall back to the az cli to set the parent.

Something like the following would be very handy

- name: Create or update the device in iothub
  azure.azcollection.azure_rm_iotdevice:
    auth_method: sas
    edge_enabled: "{{ iot_edge_enabled }}"
    name: "{{ iot_edge_device_id }}"
    hub: "{{ iot_azure_iothub_name }}"
    hub_policy_key: "{{ iot_hub_policy_key }}"
    hub_policy_name: "{{ iot_hub_policy_name }}"
    twin_tags: "{{ iot_hub_device_tags }}"
    parent_name: MyParentDeviceId # <---- new field
    state: present
Fred-sun commented 1 year ago

@vasdee You mean we need to add a module in order to set the parent device of a target iot device, right?

vasdee commented 1 year ago

Feels like it would be nicer to have it all in one, but just now looking at the existing az cli for it, it appears to be a separate call. I'd be happy with either, the less I have to fall back to the az cli within ansible, the better