Code Monkey home page Code Monkey logo

quick-ec2-instance's Introduction

quick-ec2-instance

This project is intended to act as a simple example of spinning up an AWS instance, in preparation for additional automation, for example to deploy Satellite, Openshift, Pacemaker or similar.

The instructions and playbooks in this repository:

  • Configure some AWS credentials in the Ansible Vault
  • Prepare the shell environment for the AWS dynamic inventory script
  • Create a default VPC if one does not already exist (examples for specific VPC creation are included too where explicitly defined subnets, security groups, internet gateways, routing tables or similar are required.)
  • Create an appropriately sized instance (the file system layout is kept deliberately simple, for production deployments refer to the corresponding documentation)

Contents

.
├── ansible.cfg
├── inventories
│   ├── aws
│   ├── ec2.ini
│   └── group_vars
│       └── all
│           ├── vars
│           │   └── all.yml
│           └── vault
│               └── all.yml
├── playbooks
│   ├── create-arm-ec2-instances.yml
│   ├── create-default-infrastructure.yml
│   ├── create-ec2-instances.yml
│   ├── create-specific-infrastructure.yml
│   ├── create-x86-ec2-instances.yml
│   ├── debug-infrastructure.yml
│   ├── destroy-ec2-instances.yml
│   └── templates
│       ├── config.j2
│       └── credentials.j2
└── README.md
  • inventories/aws: AWS dynamic inventory script
  • inventories/group_vars/all/vars/all.yml: inventory group vars for AWS and RHSM
  • inventories/group_vars/all/vault/all.yml: sensitive inventory group vars for AWS and RHSM
  • playbooks/create-default-infrastructure.yml: idempotently create a default AWS VPC
  • playbooks/create-specific-infrastructure.yml: idempotently create specific VPN with explicit subnets, security groups, internet gateways and routing tables
  • playbooks/create-x86-ec2-instances.yml: create x86_64 EC2 instance(s)
  • playbooks/create-arm-ec2-instances.yml: create arm EC2 instance(s)
  • playbooks/destroy-ec2-instances.yml: destroy the EC2 instance(s)
  • playbooks/debug-infrastructure.yml: debug output from VPC facts

Variables

Steps

  1. Clone the repository
$ git clone [email protected]:wmcdonald404/quick-ec2-instance.git ~/quick-ec2-instance/
  1. Define your AWS access_key, secret_key and keypair variables in a vault file

Note: vault/all.yml will contain the vaulted/encrypted values. vars/all.yml is effectively a layer of redirection so that there is a plain-text copy of the variable name to aid troubleshooting/tracing.

$ mkdir -p ~/quick-ec2-instance/inventories/group_vars/all/{vars,vault}

$ ansible-vault create ~/quick-ec2-instance/inventories/group_vars/all/vault/all.yml
$ ansible-vault edit ~/quick-ec2-instance/inventories/group_vars/all/vault/all.yml

vaulted_aws_access_key: <access_key>
vaulted_aws_secret_key: <secret_key>
vaulted_ec2_keypair: <key_pair_name>
  1. Optionally, create a vault-pass file (nb: never check this into SCM)
vi ~/.vault-pass
  1. Export environment variables required for the AWS dynamic inventory script
export AWS_ACCESS_KEY_ID=<access_key_id>
export AWS_SECRET_ACCESS_KEY=<secret_access_key>
  1. Set appropriate variables for instance_count and instance_tag:
$ vi ~/quick-ec2-instance/inventories/group_vars/all/vars/all.yml 

ec2_instance_count: 1
ec2_instance_tag:
  name: satellite
  1. Create AWS default VPC infrastructure
$ cd ~/quick-ec2-instance
$ ansible-playbook ~/quick-ec2-instance/playbooks/create-default-infrastructure.yml
  1. Refresh the inventory cache (just in case this is an iteration run and a previous instance has been cached)
$ ~/quick-ec2-instance/inventories/aws --refresh-cache
  1. Create EC2 instance
$ cd ~/quick-ec2-instance
$ ansible-playbook ~/quick-ec2-instance/playbooks/create-x86-ec2-instances.yml
  1. Note the item.dns_name value

Variations

The instance tag name can be defined on-the-fly on the command line using JSON-formatted extra variables to override inventory variables as illustrated below:

$ ansible-playbook ~/quick-ec2-instance/playbooks/create-x86-ec2-instances.yml -e '{ "ec2_instance_tag": { "name": "mytagname" } }'

Similarly, the number of instances to be provisioned can be altered on-the-fly as shown here:

$ ansible-playbook ~/quick-ec2-instance/playbooks/create-x86-ec2-instances.yml -e 'ec2_instance_count=4'

quick-ec2-instance's People

Contributors

wmcdonald404 avatar ckyriakidou avatar

Watchers

James Cloos 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.