Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend ec2_metadata_facts to get instance tags #851

Closed
1 task done
rcousens opened this issue May 31, 2022 · 6 comments
Closed
1 task done

Extend ec2_metadata_facts to get instance tags #851

rcousens opened this issue May 31, 2022 · 6 comments
Labels
feature This issue/PR relates to a feature request module module plugins plugin (any type)

Comments

@rcousens
Copy link

Summary

AWS recently added support for retrieving instance tags from the instance metadata service, see: https://aws.amazon.com/about-aws/whats-new/2022/01/instance-tags-amazon-ec2-instance-metadata-service/

A natural fit for including this functionality would be to extend ec2_metadata_facts to support retrieving instance tags, see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html#instance-metadata-ex-7 for details on how that is done.

I'd like to add the functionality, but I'm unclear what would be more acceptable to the community with regards to handling whether or not this functionality is enabled. There's two options I see:

  • A flag passed to ec2_metadata_facts to tell it to attempt to retrieve tags, and fail with error when it can't

OR

  • Assume the instance tag metadata functionality is enabled, attempt to retrieve tags, and fail silently when it's not

Which makes more sense and is in keeping with the "ethos" of the modules? My hunch is the 1st option.

Issue Type

Feature Idea

Component Name

ec2_metadata_facts.py

Additional Information

I'd be happy to write the code.

- amazon.aws.ec2_metadata_facts:
    tags: yes

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module needs_triage plugins plugin (any type) labels May 31, 2022
@alinabuzachis
Copy link
Contributor

@rcousens Thank you for this feature idea. I think the second option you listed - "Assume the instance tag metadata functionality is enabled, attempt to retrieve tags, and fail silently when it's not" makes more sense to me. Don't know what @tremble @jillr @markuman think about.

@markuman
Copy link
Member

markuman commented May 31, 2022

AWS recently added support for retrieving instance tags from the instance metadata service, see: https://aws.amazon.com/about-aws/whats-new/2022/01/instance-tags-amazon-ec2-instance-metadata-service/

Yes, and community.aws supports this already for ec2_launch_template since 3.1.0 and amazon.aws for ec2_instance the support is already in the main branch, but not released yet 🚀🚀🚀

"Assume the instance tag metadata functionality is enabled, attempt to retrieve tags, and fail silently when it's not" makes more sense to me.

Yes, +1 for the second option.

Just a few words more about accessing metadata from the instances itself

workaround

You can do it already using ansible buildin modules - more or less comfortable

    - name: get metadata token
      uri:
        url: "http://169.254.169.254/latest/api/token"
        headers:
          X-aws-ec2-metadata-token-ttl-seconds: 60
        method: PUT
        return_content: yes
      register: METADATA_TOKEN


    - name: get tag name
      uri:
        url: "http://169.254.169.254/latest/meta-data/tags/instance/Name"
        headers:
          X-aws-ec2-metadata-token: "{{ METADATA_TOKEN.content }}"
        return_content: yes
      register: TAG_NAME

prod and cons

The ec2 instances that runs ec2_metadata_facts in believing they receive their tags, must have botocore >= 1.23.30.
I think you might need this feature when you're using ansible-pull or run some plays via systemd-timer.

Another possibility to access all instance tags is via a control node that is using the dynamical aws_ec2 inventory. They are accessable via host_vars.

@tremble
Copy link
Contributor

tremble commented May 31, 2022

+1, assume it's enabled, drop a warning if it fails, and continue cleanly.

@tremble
Copy link
Contributor

tremble commented Feb 10, 2023

support was added by #1186 and should be available in release 5.1.0

@tremble tremble closed this as completed Feb 10, 2023
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
aws_kms_info: Correct deprecation of keys_attr

SUMMARY
fixup derecation of keys_attr.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_kms_info
ADDITIONAL INFORMATION
ansible-collections#838

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Jill R <None>
Reviewed-by: None <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Sep 18, 2023
aws_kms_info: Correct deprecation of keys_attr

SUMMARY
fixup derecation of keys_attr.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_kms_info
ADDITIONAL INFORMATION
ansible-collections#838

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Jill R <None>
Reviewed-by: None <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this issue Oct 24, 2023
aws_kms_info: Correct deprecation of keys_attr

SUMMARY
fixup derecation of keys_attr.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
aws_kms_info
ADDITIONAL INFORMATION
ansible-collections#838

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Jill R <None>
Reviewed-by: None <None>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request module module plugins plugin (any type)
Projects
None yet
Development

No branches or pull requests

5 participants