Skip to content

Commit

Permalink
Update result var names
Browse files Browse the repository at this point in the history
  • Loading branch information
hakbailey committed Dec 9, 2024
1 parent 9957fae commit 5a7d83b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions roles/manage_ec2_instance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Users can specify various parameters for instance configuration, including insta

This role can be combined with the [cloud.aws_ops.ec2_networking_resources role](../ec2_networking_resources/README.md) to create/delete networking resources for the instance, see [examples](#examples).

EC2 instance details and the private key (if a key pair is created) will be displayed as role output. The instance and key pair details are accessible via variables `ec2_instance_manage_create_result` and `ec2_instance_manage_key_pair_result`, respectively.

## Requirements

An AWS account with the following permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
name: "{{ manage_ec2_instance_key_name }}"
state: present
when: key_info_result.keypairs | length == 0
register: new_key_pair_result
register: ec2_instance_manage_key_pair_result

- name: Create EC2 instance with provided configuration
amazon.aws.ec2_instance:
Expand All @@ -52,15 +52,15 @@
- name: Get EC2 instance info
amazon.aws.ec2_instance_info:
instance_ids: "{{ ec2_instance.instance_ids[0] }}"
register: _ec2_instance
register: ec2_instance_manage_create_result

- name: Output details of the created EC2 instance
ansible.builtin.debug:
msg:
- "EC2 instance {{ ec2_instance.instance_ids[0] }} created successfully"
- "Instance details: {{ _ec2_instance.instances[0] }}"
- "Instance details: {{ ec2_instance_manage_create_result.instances[0] }}"

- name: Output private key if a new keypair was created
when: new_key_pair_result.key is defined
when: ec2_instance_manage_key_pair_result.key is defined
ansible.builtin.debug:
msg: "A new key pair was created for ssh access to the instance. Please save this private key for reference, it will not be accessible again: {{ new_key_pair_result.key.private_key }}"
msg: "A new key pair was created for ssh access to the instance. Please save this private key for reference: {{ ec2_instance_manage_key_pair_result.key.private_key }}"

0 comments on commit 5a7d83b

Please sign in to comment.