generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support storage of key pair into S3 bucket - Needed for running on AW…
…X (container)
- Loading branch information
Showing
6 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
- name: Ensure S3 bucket exists | ||
amazon.aws.s3_bucket: | ||
name: "{{ bucket_name }}" | ||
versioning: false | ||
state: present | ||
|
||
- name: Check if object exists into bucket | ||
amazon.aws.s3_object_info: | ||
bucket_name: "{{ bucket_name }}" | ||
object_name: "id_rsa" | ||
register: existing_obj | ||
ignore_errors: true | ||
|
||
- name: Create RSA key pair and Save Private key into S3 bucket | ||
when: existing_obj is failed | ||
block: | ||
- name: Create key pair to connect to the VM | ||
amazon.aws.ec2_key: | ||
name: "{{ deploy_flask_app_sshkey_pair_name }}" | ||
register: keypair | ||
|
||
- name: Put object into bucket | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}" | ||
mode: put | ||
object: "id_rsa" | ||
content: "{{ keypair.key.private_key }}" | ||
|
||
- name: Download object as string | ||
amazon.aws.s3_object: | ||
bucket: "{{ bucket_name }}" | ||
mode: getstr | ||
object: "id_rsa" | ||
register: downloadObj | ||
|
||
# Download RSA Key | ||
- name: Create temporary file for Private RSA key | ||
ansible.builtin.tempfile: | ||
suffix: id_rsa | ||
register: private_key | ||
|
||
- name: Save private key into file | ||
ansible.builtin.copy: | ||
content: "{{ downloadObj.contents }}" | ||
dest: "{{ private_key.path }}" | ||
mode: 0400 | ||
|
||
- name: Set variable for SSH private key file | ||
ansible.builtin.set_fact: | ||
sshkey_file: "{{ private_key.path }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters