<commit_before># Wimpy
Ansible playbook to deploy Docker containers to AWS.
The goal of this project is to provide playbooks to deploy Docker applications to EC2 instances using immutable infrastructure.
You could create a parametrized job in your CI server that will be triggered every time a tag is created in your repository (or push to master, etc).
This job would execute these playbooks using as parameters your project's name, tagged version and so on.

**After the execution of the playbooks, you will have an Auto Scaling Group with EC2 instances running docker containers with your project's code.**

## Requirements
The system running this role needs
- troposphere

## Usage
To use this role, your project repository should contain a playbook like the following

```yml
- hosts: all
  vars:
     wimpy_project_name: my_awesome_project
     wimpy_aws_vpc_id: "vpc-ed1cc588"
     wimpy_aws_keypair: "midleware"
     wimpy_aws_hosted_zone_name: "{{ vars.group_names[0] }}.spain.schibsted.io."
     wimpy_aws_elb_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
     wimpy_vpc_subnets: ["subnet-asd234sa", "subnet-bcfg234sa"]
     wimpy_aws_lc_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
  roles:
    - role: wimpy
```

When your CI server receives a push to the repository, it'll execute the playbook inside

```bash
$ ansible-playbook -i preprod deploy.yml --extra-vars "wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

The flow for every deploy is the following:
- Use `docker-compose` to build the project locally (e.g running gradle, npm, etc). Your repository must contain a `docker-compose-build.yml` file that generates an artifact.
- Create docker image using project's `Dockerfile` that copies the artifact generated on the previous step into the container image.
- Push image to Docker Registry.
- Create new Launch Configuration using CoreOS AMI. The cloud-init will start the app's container for the deployed version.
- Make sure there is an Auto Scaling Group with the created Launch Configuration.
- If there were running instances in the Auto Scaling group, replace these instances with new instances using the new AMI.

## Required parameters
The only required parameters that have no default values are:
```
- wimpy_project_name: "my_awesome_project" # Name of your project
- wimpy_release_version: "2.5" # Version being deployed
- wimpy_deployment_environment: "preprod" # Environment where to deploy
- wimpy_aws_vpc_id: "vpc-123456" # AWS VPC to use
- wimpy_aws_keypair: "authentication" # Key pair to put on EC2 instances
- wimpy_aws_hosted_zone_name: "example.com" # Hosted zone where to create the DNS record for your project
- wimpy_aws_elb_security_groups: ["sg-asd234sa"]
- wimpy_vpc_subnets: ["subnet-asd234sa", "subnet-bcfg234sa"]
- wimpy_aws_lc_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
```
Traditionally, `wimpy_release_version` will contain the new version pushed to the repository that is being built on Jenkins.

## Authentication
### AWS
This role expects to be runned on a server with a IAM Instance Role with permissions to create and modify AWS resources.

```bash
$ ansible-playbook -i preprod deploy.yml --extra-vars "wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

You can also pass a `boto_profile` parameter to use a boto_profile to authenticate yourself.

```bash
$ ansible-playbook -i global_pre_hosts deploy.yml --extra-vars "boto_profile=profile_with_permissions wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

### Docker Registry
Currently, Docker only way to authenticate a request to a Docker Registry is using the docker login command. These playbooks will place the config file that Docker generates whenever you login in the command line. A "deploy" user should be created to make it easier to deploy from a CI server.

## Environments
The `wimpy_deployment_environment` variable is used to determine which file from your repository to pass to `docker-compose`. Typically, you'd have a different `docker-compose` file for each environment.
<commit_msg>typos<commit_after># Wimpy
Ansible playbook to deploy Docker containers to AWS.
The goal of this project is to provide playbooks to deploy Docker applications to EC2 instances using immutable infrastructure.
You could create a parametrized job in your CI server that will be triggered every time a tag is created in your repository (or push to master, etc).
This job would execute these playbooks using as parameters your project's name, tagged version and so on.

**After the execution of the playbooks, you will have an Auto Scaling Group with EC2 instances running docker containers with your project's code.**

## Requirements
The system running this role needs
- troposphere

## Usage
To use this role, your project repository should contain a playbook like the following

```yml
- hosts: all
  vars:
     wimpy_project_name: my_awesome_project
     wimpy_aws_vpc_id: "vpc-ed1cc588"
     wimpy_aws_keypair: "midleware"
     wimpy_aws_hosted_zone_name: "{{ vars.group_names[0] }}.spain.schibsted.io."
     wimpy_aws_elb_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
     wimpy_vpc_subnets: ["subnet-asd234sa", "subnet-bcfg234sa"]
     wimpy_aws_lc_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
  roles:
    - role: wimpy
```

When your CI server receives a push to the repository, it'll execute the playbook inside

```bash
$ ansible-playbook -i preprod deploy.yml --extra-vars "wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

The flow for every deploy is the following:
- Use `docker-compose` to build the project locally (e.g running gradle, npm, etc). Your repository must contain a `docker-compose-build.yml` file that generates an artifact.
- Create docker image using project's `Dockerfile` that copies the artifact generated on the previous step into the container image.
- Push image to Docker Registry.
- Create new Launch Configuration using CoreOS AMI. The cloud-init will start the app's container for the deployed version.
- Make sure there is an Auto Scaling Group with the created Launch Configuration.
- If there were running instances in the Auto Scaling group, replace these instances with new instances using the new AMI.

## Required parameters
The only required parameters that have no default values are:
```
- wimpy_project_name: "my_awesome_project" # Name of your project
- wimpy_release_version: "2.5" # Version being deployed
- wimpy_deployment_environment: "preprod" # Environment where to deploy
- wimpy_aws_vpc_id: "vpc-123456" # AWS VPC to use
- wimpy_aws_keypair: "authentication" # Key pair to put on EC2 instances
- wimpy_aws_hosted_zone_name: "example.com" # Hosted zone where to create the DNS record for your project
- wimpy_aws_elb_security_groups: ["sg-asd234sa"]
- wimpy_vpc_subnets: ["subnet-asd234sa", "subnet-bcfg234sa"]
- wimpy_aws_lc_security_groups: ["sg-asd234sa", "sg-ifufd34sa"]
```
Traditionally, `wimpy_release_version` will contain the new version pushed to the repository that is being built on Jenkins.

## Authentication
### AWS
This role expects to be run on a server with a IAM Instance Role with permissions to create and modify AWS resources.

```bash
$ ansible-playbook -i preprod deploy.yml --extra-vars "wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

You can also pass a `boto_profile` parameter to use a boto_profile to authenticate yourself.

```bash
$ ansible-playbook -i global_pre_hosts deploy.yml --extra-vars "boto_profile=profile_with_permissions wimpy_release_version=2.3 wimpy_deployment_environment=preprod"
```

### Docker Registry
Currently, the only way to authenticate a request to a Docker Registry is using the docker login command. These playbooks will place the config file that Docker generates whenever you login in the command line. A "deploy" user should be created to make it easier to deploy from a CI server.

## Environments
The `wimpy_deployment_environment` variable is used to determine which file from your repository to pass to `docker-compose`. Typically, you'd have a different `docker-compose` file for each environment.

{'fraction_non_alphanumeric': 0.07062285434036292, 'fraction_numerical': 0.012751348700343305, 'mean_word_length': 5.019926199261993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3561288', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2374, 'n_words': 982}