Hello all,
I would like to ask about the sense of the default values of the parameters of Ansible modules.
Let me give you an example, let’s say there is a module to manage Virtual Machines(VM), the module looks for example like this:
module_vm:
name: myvm
memory: 1GiB
When you run this module and the VM don’t exist it will create it with 1GiB.
Now let’s say the ‘memory’ parameter has default value of 2GiB.
module_vm:
name: myvm
Now I will run this^ playbook which has removed the ‘memory’ parameter.
If the ‘memory’ parameter is idempotent, then the VM should be updated to 2GiB of memory.
All seems OK… but…
If I will create a VM like this:
module_vm:
name: myvm
cpu: 5
memory: 4GiB
cluster: west
And the module has following default values:
memory: 1GIB
cpu: 1
cluster: mycluster
Then when I for example want to update all of my VMs to 8GiB of memory I will create folllowing task:
module_vm:
name: {{ item }}
memory: 8GiB
with_items:
- {{ vms_to_update }}
The module will update the memory to 8GiB and the cpu and cluster to default values.
So in such case default values doesn’t make sense to me, because it’s not clear if the user want’s to have the value of cpu and cluster updated or not.
Is there any best practise for this? What is the correct usage of the update?
Thanks a lot,
Ondra