cloudscale-ch/ansible-collection-cloudscale

Allow name, uuid or object as argument for parameters

Closed this issue · 2 comments

ctx commented

Some users might want to use fixed names for their resources in their playbooks:

    - name: Create volume
      cloudscale_ch.cloud.volume:
        name: 'my_ssd_volume'
        ...

    - name: Start a server
      cloudscale_ch.cloud.server:
        name: 'my_server'
        ...

    - name: Attach volume to server
      cloudscale_ch.cloud.volume:
        name: 'my_ssd_volume'
        servers:
          - 'my_server'

Other users don't want to dig into the structure of return values to pass a uuid to another task:

    - name: Create volume
      cloudscale_ch.cloud.volume:
        name: my_ssd_volume
        ...
      register: volume

    - name: Start a server
      cloudscale_ch.cloud.server:
        name: my_server
        ...
      register: server

    - name: Attach volume to server
      cloudscale_ch.cloud.volume:
        name: "{{ volume }}"
        servers:
          - "{{ server }}"

Create a function that can compare uuid, name or an object with a given object.

Spot all parameters that take only name, uuid or an object and make it possible to use any.

resmo commented

Ansible does not work this way:

Ansible needs a human-defined identifier to find the resources it creates.

You (and Ansible) cannot know the ID (UUID) generated by the API in advance. If you have already created a resource with an ID and want to use that ID in playbooks, the resource with that ID will not be recreated once the resource is deleted. So, there would be no idempotency.

There are modules in the AWS namespace I am aware of allow to give an ID but the ID has to be looked up by a name in a previous task, which we do in one task. Or hardcoded after the resource was created with the downside I already tried to explain.

That is why I am against implementing this "feature"

ctx commented

Thank you for your answer.