cloudscale-ch / ansible-collection-cloudscale

cloudscale.ch Ansible Collection
https://galaxy.ansible.com/cloudscale_ch/cloud
GNU General Public License v3.0
7 stars 3 forks source link

Allow name, uuid or object as argument for parameters #56

Closed ctx closed 1 year ago

ctx commented 3 years ago

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 2 years ago

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 1 year ago

Thank you for your answer.