GithubHelp home page GithubHelp logo

infrastructure-tf-ansible's Introduction

Full infrastructure created by Terraform and configured by Ansible on WSL2

The whole project has been divided onto two parts: Terraform (IaC) and Ansible (ansible). The end result are 3 EC2 instances with Apache HTTP Server installed on them and network traffic load balanced by Application Load Balancer.

Terraform

The code shown in IaC folder provisions 3 EC2 instances with 3 subnets and Application Load Balancer. AMI, instance type and private key name (in ec2.tf file), as well as region, access and secret key (in provider.tf file) needs to be provisioned by the user. All the files provided in IaC folder need to be compiled within the same folder by using terraform init and terraform apply or using terraform module.

Ansible

The code shown in ansible folder configures 3 EC2 instances created earlier. This implementation uses roles and the whole tree needs to look as follows:

.
├── roles
│   └── server
│       └── tasks
│           └── main.yml
├── server.yml
├── .inventory
│   └── my_aws_ec2.yml
├── ansible.cfg

The roles/server/tasks/ directory follows the structure which can be found here. It consists of a main.yml file, which hold the whole server configuration, that allows printing of server ip (used to check if ALB works correctly) by using ansible_hostname. This task is called from server.yml, which consists of hosts part (instances to be connected to), privelage escalation using become: true and roles, which describes which role shall be used.
In order to connect to the EC2 instance, ansible.cfg needs to be properly configured. First of all, aws_ec2 plugin shall be installed and remote_user set to ec2-user. Then, path to the private key that has been created and downloaded from AWS, as well as, path to the inventory file shall be described.
Within the inventory file, that is my_aws_ec2.yml all the information like plugin, regions, filters (used to make sure we use only instances we want, rely on tags created via terraform), access and secret key need to be specified.
Files like ansible.cfg may not be installed automatically. If this situation happens, they should be added manually.

What needs to be installed

  1. Terraform
  2. Ansible
  3. AWS_EC2 plugin

infrastructure-tf-ansible's People

Contributors

1ms-ms avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.