I’ve tried a LOT of things now, and have come to the conclusion that ec2_instance_facts requires a literal filter name, at least in the case of “tags:Name”.
This makes that filter essentially useless
Please, can someone tell me I’m wrong, and how me how to filter on a tag:value pair passed in as a variable?
When I use that, I get the same error as before: An error occurred (InvalidParameterValue) when calling the DescribeInstances operation: The filter ‘GroupName’ is invalid
(“GroupName” is the value in my variable tag_name)
If you actually TRIED it and it worked, do let me know.
The second last one (no space after the first colon) gives a different message: “argument filters is of type <type ‘str’> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value”}
These work - but they have a literal filter name
“tag:GroupName” : “DEMO”
“tag:GroupName” : “{{tag_value }}”
Thanks, K.
PS: There was a typo in my last message. I meant to write “… at least in the case of ‘tag:Name’”
Thank you! Those work, indeed they do. What does that “~” syntax mean?
The reason I said your earlier solution did not work one is that you did not in your first answer include the secret sauce of prefixing “tag”: to the tag name in the tag_name variable itself. When I do that, the first variant works. I should have tried that, it seems obvious in hindsight
The second variant is nicer IMHO because it keeps the specifics of the filter syntax in the filter clause itself, and the actual tag name can be passed in.
Thank you so much for your assistance. The solution using ec2_instance_facts is way simpler than the solution I had working with ec2.py.
While they’re often interchangeable, developing a habit of using the concatenation operator means that you don’t have to worry about or code around the situations where they’re not.
TASK [Addition isn't concatenation] ********************************************
ok: [localhost] => {
"13 + 37": "50"
}
TASK [Concatenation is concatenation] ******************************************
ok: [localhost] => {
"13 ~ 37": "1337"
}
TASK [Concatenation handles mixed types] ***************************************
ok: [localhost] => {
"13 ~ '37'": "1337"
}
TASK [It's possible to do the coercion manually, but who wants to do that?] ****
ok: [localhost] => {
"13 | string + '37'": "1337"
}
TASK [Addition doesn't like mixed types] ***************************************
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{13 + '37'}}): unsupported operand type(s) for +: 'int' and 'str'"}