ansible-collections / amazon.aws

Ansible Collection for Amazon AWS
GNU General Public License v3.0
304 stars 332 forks source link

ec2_metadata_facts: Add support to query instance tags + values #2293

Open drewoconnor opened 6 days ago

drewoconnor commented 6 days ago

Summary

https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_metadata_facts_module.html#return-ansible_facts/ansible_ec2_instance_tags_keys

States that it returns the keys. But, there is no way to get the values.

Can we add a way to get the tag Values?

Issue Type

Feature Idea

Component Name

ec2_metadata_facts

Additional Information

Code of Conduct

tremble commented 6 days ago

It's currently not very "obvious" but they are returned...

Running the integration test we have for this module:

TASK [amazon.aws.ec2_metadata_facts] *******************************************
...
ok: [34.239.124.147] => {
    "ansible_facts": {
        "ansible_ec2_ami_id": "ami-07320b1482d6ac29f",
...
        "ansible_ec2_instance_tags_keys": [
            "Name",
            "camelCaseKey",
            "snake_case_key"
        ],
...
        "ansible_ec2_tags_instance_Name": "ansible-test-28009695-ec2-metadata-facts",
        "ansible_ec2_tags_instance_camelCaseKey": "aCamelCaseValue",
        "ansible_ec2_tags_instance_snake_case_key": "a_snake_case_value",
        "ansible_ec2_user_data": "None"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "metadata_token_ttl_seconds": 240
        }
    }
}

The tag values are accessible under ansible_ec2_tags_instance_<tag_name>, so this is more a case of missing documentation bug than a missing feature.

Originally it wasn't possible to return dictionaries as fact values, this is now possible, so it might make sense to support returning the tags as a dict...