项目作者: pythianali

项目描述 :
Terraform Ansible ELK Stack
高级语言: HCL
项目地址: git://github.com/pythianali/TF-Ansible-ELK.git
创建时间: 2017-03-28T03:16:02Z
项目社区:https://github.com/pythianali/TF-Ansible-ELK

开源协议:

下载


Terraform-Ansible-ELK Stack

Note this stack is a continual work in progress and capabilities will change over time

Table of Contents

Overview

This stack is designed to launch an ELK stack in an AWS environment using Terraform and Ansible for infrastructure creation and provisioning.

The stack consists of the following components:

  • Public VPC
  • Internet Gateway
  • NAT Gateway
  • Security Groups
  • Instances (one each for now)
    • Elasticsearch
    • Logstash
    • Kibana

Requirements

  • Access to an AWS account
  • Ubuntu 16.04 AMI. More options to follow later
  • AWSCLI installed locally and properly configured
  • Python installed locally
  • Ansible installed locally.
  • Terraform installed locally.

Notes about build environment

The following versions of tools and OS were used to initially develop this stack

  • Fedora 24
  • Terraform 0.7.9
  • Ansible 2.2.1.0
  • Python 2.7.13
  • awscli 1.11.21

Ansible Configuration

Currently testing these options in /etc/ansible/ansible.cfg for a reliable fact store. See This for details on how this works.

  1. gathering = smart
  2. fact_caching = jsonfile
  3. fact_caching_connection = /tmp/
  4. fact_caching_timeout = 86400

Terraform.py submodule

Terraform.py is a neat submodule that we use to dynamically create an EC2 inventory for ansible to use in place of its inventory file. It can be run at the CLI and will return IP and hostname values for the running environment.

Initialization Steps

Grab the repository

  1. git clone git@github.com:pythianali/TF-Ansible-ELK.git MyProjectFolder

Grab the submodules

  1. cd MyProjectFolder
  2. git submodule update --init --recursive --remote

Create a credentials file in the project root. Update values accordingly for AWS keys. In this case creds.tf was used.

  1. variable "AWS_ACCESS_KEY" {
  2. default = "MyAccessKEY"
  3. }
  4. variable "AWS_SECRET_KEY" {
  5. default = "MySecretKEY"
  6. }
  7. variable "KEY_NAME" {
  8. default = "TF-Ansible-ELK"
  9. }
  10. variable "LOCAL_KEY_NAME" {
  11. default = "keys/TF-Ansible-ELK.pem"
  12. }
  13. variable "INSTANCE_USERNAME" {
  14. default = "ubuntu"
  15. }

Create a keys directory and add the EC2 keypair needed to access the instances. The directory structure looks like below when completed

  1. .
  2. ├── ansible
  3. ├── ansible-elasticsearch
  4. └── playbooks
  5. ├── creds.tf
  6. ├── instance.tf
  7. ├── keys
  8. └── TF-Ansible-ELK.pem
  9. ├── provider.tf
  10. ├── README.md
  11. ├── sg.tf
  12. ├── terraform.py
  13. ├── LICENSE
  14. ├── README.md
  15. ├── requirements.txt
  16. ├── terraform.py
  17. └── tests
  18. ├── vars.tf
  19. └── vpc.tf

Launching the Stack

To launch the stack you can run the following commands

  1. terraform plan
  2. terraform apply

Plan provides an overview of changes to be applied and Apply will actually apply those changes

Destroying the stack

To destroy the stack simply run:

  1. terraform destroy