Git Product home page Git Product logo

web-server-by-terraform-and-ansible's Introduction

Provision web server by Terraform and Ansible

This repository includes the Terraform and Ansible files to provision following components,

  • An EC2 instance exposed port 80 and 22
  • Install nginx package by yum package manager
  • Any neccessary resources on AWS

Version tested

  • Terraform v1.5.7
  • Ansible 2.16.2

Usage

Clone this repository and install Terraform and Ansible to your executing machine, and finish the setup of aws configure before use.

Please note that you have to execute Terraform script frist, then Ansible playbook, as there will be an inventory file auto-generated from your Terraform execution.

Terraform

  1. cd to folder web-server-by-terraform-and-ansible/terraform
  2. Create a new file named terraform.tfvars with following content,
ec2_keypair_public_key="<Public key of your SSH key pair>"

# Replace <Public key of your SSH key pair> with the public key of your own SSH key pair.
# It will be used provision the EC2 instance and allow Ansible to authenticate
  1. (optional) Update the default value ~/.ssh/id_rsa to your private key file path in ansible_ssh_private_key_file from ../ansible/inventory.template
  2. Initialize terraform dependencies by
terraform init
  1. Get the list of resources being created by
terraform plan
  1. Create the resources on AWS by
terraform apply

After successful execution, you should see a newly created file named inventory located in your ../ansible directory. Please do not delete it as it will be the inventory file for the Ansible playbook.

Ansible

  1. cd to folder web-server-by-terraform-and-ansible/ansible
  2. Install nginx package and start the service on newly created EC2 instance by
ansible-playbook -i inventory install_nginx.yaml

web-server-by-terraform-and-ansible's People

Contributors

yukccy avatar

Watchers

 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.