Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Added Efs #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ asg_launch_config_key_name: ""
asg_launch_config_instance_profile_name: ""
```

### EFS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a core module and therefore documentation should be in the custom-instrastructure folder.


Here you define characteristics of your Elastic File Storage so that instances can boot up with the right setup one would expect.
The EFS will only create if efs_create is true.

The following variables are mandatory:

| variable name | importance | default | description |
|---------------------------------|------------|------------------|--------------------------------------------------------------------------------------------------|
| efs_create | **mandatory** | false | If the EFS cluste will be created. |
| efs_name | **mandatory** | "myefs" | The name of the EFS cluster. |
| efs_data_dir | **mandatory** | "data" | The directory the efs will be mounted on. |
| efs_security_group | **mandatory** | [] | The default security group of the vpn. |


**Note** By default the port to nfs is blocked, so you will either need to add the port exception to your default security group or will need to add your default security group of your vpn to your asg_additional_security_groups_env variable

**Note** The name field will not populate. This bug has been resolved in 2.4.0 of ansible

# Service

Expand Down
11 changes: 11 additions & 0 deletions example-cluster/infrastructure/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ asg_additional_security_groups: "{{ asg_additional_security_groups_env | default


ecs_cluster_name: "{{ cluster_name }}"


efs_commands: "sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone){{ efs_instance.efs.mount_point }} data"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go in the readme you will create in custom-infrastructure. This is not a core module so the examples shouldn't include extra modules



additional_user_data_bootcmd: |
- sudo yum install -y nfs-utils
- sudo mkdir data
- echo "{{ efs_commands }}"
- " {{ efs_commands }} "
- echo after efs
8 changes: 5 additions & 3 deletions infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- ["{{ cluster_name }}/infrastructure/{{ env }}.vault.yml", "{{ cluster_name }}/infrastructure/{{ env }}.yml"] # load vault if exists
- "{{ cluster_name }}/infrastructure/{{ env }}.yml" # include environment specific variables
roles:
- roles/aws.ec2-security-groups # create security groups
- roles/aws.ec2-autoscaling-group # create the auto scaling group
- roles/aws.ecs-cluster # create ecs cluster
- role: custom-infrastructure
when: custom_task_files | default([])
- role: roles/aws.ec2-security-groups # create security groups
- role: roles/aws.ec2-autoscaling-group # create the auto scaling group
- role: roles/aws.ecs-cluster # create ecs cluster
1 change: 1 addition & 0 deletions roles/aws.ec2-autoscaling-group/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- /usr/bin/easy_install pip
- /usr/local/bin/pip install --upgrade boto3 boto awscli requests psutil {{ asg_additional_python_pip_packages }}
{{ asg_additional_user_data_bootcmd }}
{{ _efs_additional_bootcmd }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

efs is not a core module, therefore core modules shouldn't be changed. Instead, leverage the already available asg_additional_user_data_bootcmd in your playbook


- name: Set write_files
set_fact:
Expand Down
22 changes: 22 additions & 0 deletions roles/custom-infrastructure/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

### This is used to create efs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to go under your files/efs.yml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use "defaults" for custom modules

# An efs needs subnets and a default security group for the vpc

efs_create: false
efs_name: "myefs"
efs_data_dir: "data"
efs_security_group: []

_efs_mount_command: ""

_efs_additional_bootcmd: |
- sudo yum install -y nfs-utils
- sudo mkdir "{{ efs_data_dir }}"
- echo before efs
- echo "{{ _efs_mount_command }}"
- " {{ _efs_mount_command }} "
- echo after efs

_efs_no_bootcmd: |
- echo no efs loaded
4 changes: 4 additions & 0 deletions roles/custom-infrastructure/files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Custom files

Add any custom files here, just like you would for any other role.
An example to look at would be the role aws.ec2-autoscaling-group
31 changes: 31 additions & 0 deletions roles/custom-infrastructure/tasks/efs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---

- name: Populate efs targets
set_fact:
_efs_targets: "{{ _efs_targets|default([]) + [ {'subnet_id': item, 'security_groups': efs_security_group } ] }}"
with_items: "{{ asg_subnets_env }}"

- debug: var=_efs_targets


# EFS provisioning
- name: Create EFS
efs:
state: present
name: "{{ efs_name }}"
profile: "{{ aws_profile }}"
tags:
Name: "{{ efs_name }}"
Purpose: file-storage
targets: "{{ _efs_targets }} "
register: efs_instance
when: efs_create

- name: Populate mount command
set_fact:
_efs_mount_command: "sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone){{ efs_instance.efs.mount_point }} {{ efs_data_dir }}"
when: efs_create

- name: Populate additional command
set_fact:
_efs_additional_bootcmd: "{{ efs_create | ternary(_efs_additional_bootcmd, _efs_no_bootcmd) }}"
5 changes: 5 additions & 0 deletions roles/custom-infrastructure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# Make sure to create a file named <service_name>.yml under the tasks directory
- name: "Include infrastructure custom tasks"
include: "{{ item }}"
with_items: "{{ custom_task_files }}"
9 changes: 9 additions & 0 deletions roles/custom-infrastructure/tasks/postgres-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed now is it?

# custom tasks file for postgres-example
- name: "Include any custom task for your service here. These will be executed before any other template"
debug:
msg: "Hi from: {{ postgres_hello_world }}"

- name: "Export some result to be used by other tasks"
set_fact:
postgres_custom_label: "This variable is accessible from the other roles now"
4 changes: 4 additions & 0 deletions roles/custom-infrastructure/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Templates

Any custom templates you might need for your tasks
look at aws.ec2-autoscaling-group for an example