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

add metadata options to ec2 template #322

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- ec2_launch_template - added ``metadata_options`` parameter to support changing the IMDS configuration for instances (https://github.com/ansible-collections/community.aws/pull/322).
34 changes: 34 additions & 0 deletions plugins/modules/ec2_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@
U(http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html#instancedata-add-user-data)
documentation on user-data.
type: str
metadata_options:
description:
- Configure EC2 Metadata options.
- For more information see the IMDS documentation
U(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html).
type: dict
version_added: 1.5.0
suboptions:
http_endpoint:
type: str
description: >
This parameter enables or disables the HTTP metadata endpoint on your instances.
choices: [enabled, disabled]
default: 'enabled'
http_put_response_hop_limit:
type: int
description: >
The desired HTTP PUT response hop limit for instance metadata requests.
The larger the number, the further instance metadata requests can travel.
default: 1
http_tokens:
type: str
description: >
The state of token usage for your instance metadata requests.
choices: [optional, required]
default: 'optional'
'''

EXAMPLES = '''
Expand Down Expand Up @@ -636,6 +662,14 @@ def main():
enabled=dict(type='bool')
),
),
metadata_options=dict(
type='dict',
options=dict(
http_endpoint=dict(choices=['enabled', 'disabled'], default='enabled'),
http_put_response_hop_limit=dict(type='int', default=1),
http_tokens=dict(choices=['optional', 'required'], default='optional')
)
),
network_interfaces=dict(
type='list',
elements='dict',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- block:
- name: metadata_options
ec2_launch_template:
name: "{{ resource_prefix }}-test-metadata"
metadata_options:
http_put_response_hop_limit: 1
http_tokens: required
state: present
register: metadata_options_launch_template
- name: instance with metadata_options created with the right options
assert:
that:
- metadata_options_launch_template is changed
- "metadata_options_launch_template.latest_template.launch_template_data.metadata_options.http_put_response_hop_limit == 1"
- "metadata_options_launch_template.latest_template.launch_template_data.metadata_options.http_tokens == 'required'"
always:
- name: delete the template
ec2_launch_template:
name: "{{ resource_prefix }}-test-metadata"
state: absent
register: del_lt
retries: 10
until: del_lt is not failed
ignore_errors: true
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- include_tasks: cpu_options.yml
- include_tasks: iam_instance_role.yml
- include_tasks: versions.yml
- include_tasks: instance-metadata.yml

always:

Expand Down