Giter Site home page Giter Site logo

gce-demo-ansible's Introduction

gce-demo-ansible

This is the supporting documentation for Using Ansible with Google video.

The goal of this repository is to provide the extra detail necessary for you to completely replicate the recorded demo. The video's main goal is to show a quick, fully working demo without bogging you down with all of the required details so you can easily see the "Good Stuff".

So for interested viewers wanting to replicate the demo on their own, this repository contains all those necessary details.

Google Cloud Platform Project

  1. You will need to create a Google Cloud Platform Project as a first step. Make sure you are logged in to your Google Account (gmail, Google+, etc) and point your browser to https://console.developers.google.com/. You should see a page asking you to create your first Project.

  2. When creating a Project, you will see a pop-up dialog box. You can specify custom names but the Project ID is globally unique across all Google Cloud Platform customers.

  3. It's OK to create a Project first, but you will need to set up billing before you can create any virtual machines with Compute Engine. Look for the Billing link in the left-hand navigation bar.

  4. In order for ansible to create Compute Engine instances, you'll need a Service Account created for the appropriate authorization. Navigate to APIs & auth -> Credentials and then Create New Client ID. Make sure to select Service Account, or generate a new one. Download the P12 private key save the file (the passphrase is notasecret). Once you save the key file, make sure to record the Email address that ends with @developer.gserviceaccount.com since this will be required in the Ansible configuration files.

  5. Next you will want to install the Cloud SDK and make sure you've successfully authenticated and set your default project as instructed.

  6. You will also need to make sure and set up SSH keys that will allow you to access your Compute Engine instances. You can either manually generate the keys or you can use gcutil ssh to access an existing Compute Engine instance and it will handle generating the keys and uploading them to the metadata server. For the sake of this demo, it is assumed you have opted to use gcutil ssh and your default private key is $HOME/.ssh/google_compute_engine.

Software

  1. Install Ansible with the running from source instructions.

  2. Install libcloud (v0.14.1 or greater). Note, you may need to ensure you have Python development packages installed. On Debian-7 for instance, you will want to first install both the build-essential and python-dev packages.

    pip install apache-libcloud
    
  3. For the purposes of the demo, you can set a couple of environment variables to simplify your commands and SSH interactions.

    export ANSIBLE_HOSTS=ansible_hosts
    export ANSIBLE_HOST_KEY_CHECKING=False
    

Ansible demo setup

  1. Check out this repository so that you can use pre-canned configuration and demo files.

    cd $HOME
    git clone https://github.com/wzzrd/gce-demo-ansible
    
  2. You will need to convert the Service Account private key file from the PKCS12 format to the RSA/PEM file format. You can do that with the openssl utility,

    openssl pkcs12 -in /path/to/original/key.p12 -passin pass:notasecret -nodes -nocerts | openssl rsa -out /path/to/pkey.pem
    
  3. Edit the group_vars/auth file and specify your Project ID in the pid variable, Service Account email address in the email variable, and the location of your converted private key in the pem variable.

    ---
    # Google Compute Engine required authentication global variables
    pid: YOUR_PROJECT_ID
    email: YOUR_SERVICE_ACCOUNT_EMAIL
    pem: /path/to/your/pkey.pem
    

Demo time!

You've now completed all of the necessary setup to replicate the demo as shown on the video. Now, you'll use ansible-playbook to create and bootstrap the instances, install Apache, and set up a Compute Engine load-balancer.

Run the playbook

Use the ansible-playbook command to create the instances based on the attributes in the configuration files. For the four instances, this should take roughly 2 minutes to create the new Compute Engine instances

ansible-playbook ...
  1. The output from this command will display the public IP address associated with your new load-balancer. You can also look in the Developers Console under the Load-Balancer section and look at your Forwarding Rules.

  2. Ok, let's test it out! Put the public IP address of your load-balancer into your browser and take a look at the result. Within a few seconds you should start to see a flicker of pages that will randomly bounce across each of your instances.

    For the demo, a javascript function is set to fire when the page loads that pauses for a half-second, and then reloads itself. Since we installed a modified Apache configuraiton file to disable client-side caching and we enabled Apache's mod_headers, each "reload" results in a new HTTP request to the page. This is just a fancy hands-free way of asking you to do a "hard refresh" of the load-balancer IP address in order to see the cycling between instances.

All done!

That's it for the demo. There is a lot of other functionality for Compute Engine in Ansible. Please take a look at the gce* modules for a full set of modules and instructions.

Cleaning up

When you're done with the demo, make sure to tear down all of your instances and clean-up. You will get charged for this usage and you will accumulate additional charges if you do not remove these resources.

Fortunately, you can use the clean-up.yml playbook for destroying these demo Compute Engine resources. The following command can be used to destroy all of the resources created for this demo.

ansible-playbook ... clean-up.yml

Troubleshooting

  • Make sure you have the latest libcloud (the pip install is probably best) installed.

Contributing

This specific project is a fork of https://github.com/GoogleCloudPlatform/compute-video-demo-ansible. I'm probably not going to actively maintain or update this to make this run with anything but RHEL. Please look upstream for that.

If you have patches to make this specific fork work (better), then I'm all ears :)

License

All files in this repository are under the Apache License, Version 2.0 unless noted otherwise.

gce-demo-ansible's People

Watchers

Maxim Burgerhout 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.