Hello,
I'm trying to create a helper role to raise ec2 instances, and I stumbled in a problem where I wanted to deleted or ignore some module options, based on the role vars.
First, let's say I have a playbook like this.
---
- name: Raise ec2 instance
ec2:
key_name: my_key
instance_type: m1.medium
image: i999999
region: us-east-1
zone: us-east-1e
wait: 1000
count_tags:
tag: value
exact_count: "{{my_count}}"
If I wanted to ignore the 'exact_count' option one may think that if you set 'my_count' to 'null' or '!!null' it will be interpreted as 'None', the default value for that option, and the module will behave as if it was not set. But because of this issue, which created
this code
, the interpreter now translates the None values to a empty string, which then makes the interpreter crash like so.
TASK: [aws-instance | Raise ec2 instance] ***************************
failed: [localhost] => {"failed": true, "parsed": false}
Traceback (most recent call last):
File "/home/user/.ansible/tmp/ansible-tmp-9999999999.99-999999999999999/ec2", line 2962, in <module>
main()
File "/Users/user/.ansible/tmp/ansible-tmp-9999999999.99-999999999999999/ec2", line 1164, in main
['exact_count', 'instance_ids']
File "/home/user/.ansible/tmp/ansible-tmp-9999999999.99-999999999999999/ec2", line 1504, in __init__
self._check_argument_types()
File "/home/user/.ansible/tmp/ansible-tmp-9999999999.99-999999999999999/ec2", line 2160, in _check_argument_types
self.params[k] = int(value)
ValueError: invalid literal for int() with base 10: ''
FATAL: all hosts have already failed -- aborting
IMHO this is unwanted behaviour, since there is no way to unset a module option or even ignore then. I don't know if I'm missing something, but if I do, please show me :)
Thanks,