A tutorial with video and code taking the user from AWS machine creation to their first deployment using Ansible
Python Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
ansible_tutorial
docs
githooks
slides
src
tests
.gitignore
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
COOKIECUTTER_CREDIT
HISTORY.rst
LICENSE
MANIFEST.in
Makefile
README.rst
develop_requirements.txt
requirements.txt
setup.cfg
setup.py
tox.ini

README.rst

Ansible Hands-On Training

A tutorial with video and code taking the user from AWS machine creation to their first deployment using Ansible

Project and Build Status

Travis tests Updates Python 3 Documentation Status

This Repository is now out of date. This was written against an older version of Ansible. The build looks like it passes, but that is because this is out of date. I am writing this note on 18-May, 2018 and hope to get to upgrading this repository to work with current versions of Ansible. This issue tracks:

https://github.com/glenjarvis/ansible_tutorial/issues/78

Welcome

A tutorial with video and code taking the user from AWS machine creation to their first deployment using Ansible

Successfully automating your machines in the cloud using Ansible

Videos of Talk

Prerequisite Talks
Slow Walkthrough

Same material / Digestible pace / Longer Video:

Fast Overview

Same material / Quickly covered / Shorter Video:

Practice Sessions

This Repository is now out of date. This was written against an older version of Ansible and hasn't yet been updated. I am writing this note on 18-May, 2018 and hope to get to upgrading this repository to work with current versions of Ansible. This issue tracks:

https://github.com/glenjarvis/ansible_tutorial/issues/78

Hands-On Training
  • No sessions currently scheduled

Talk description

As we have seen with the previous talk, "Red Pill, Blue Pill Virtual Machines and Virtual Environments" (GitHub / YouTube), we can create virtual machines in the cloud.

But, how do you "stamp" those machines differently? If you need to build a web server, mail server, DNS server, and load balancer, each machine may have the same base image but needs to be configured differently.

If you manually configure those machines, what happens when you suddenly have a surge in traffic and need four more web servers? Or, what if one finds a vulnerability in a library like Heartbleed in OpenSSL? A very safe option would be to rebuild these machines from scratch. If they were built manually, rebuilding these machines within minutes from scratch would be daunting, tedious and error prone.

There are several tools that have been built to fix this problem. Two of the most popular tools, Chef and Puppet, are written in the Ruby programming language. And, especially for the most popular, Chef, one needs somewhat of a familiarity with that language to use the tool.

There are two more tools that are written in Python and are growing in popularity: Salt and Ansible. Ansible requires the least amount of set-up (if any) and has the simplest infrastructure (it simply uses commands over ssh like Fabric does). Ansible is the easiest tool to get started with if you are new in the machine build automation frameworks.

We will start with a newly built machine and obtain it's public IP address. We will configure the ansible_hosts file with the IP address, and add/build plays (like recipes) to gradually configure that machine so that it is a Django web server running in the cloud. When we are finished, we should have a running machine and a recipe to easily build a seconded machine with a few keystrokes.

P.S. If you haven't previously built an Amazon Web Instance, I highly recommend watching this video in advance of the talk.

Getting Started (Installing and following-along)

This Repository is now out of date. This was written against an older version of Ansible and hasn't yet been updated. I am writing this note on 18-May, 2018 and hope to get to upgrading this repository to work with current versions of Ansible. This issue tracks:

https://github.com/glenjarvis/ansible_tutorial/issues/78

  1. Clone this repo to the directory you would like to have your work in.

    $ git clone https://github.com/glenjarvis/ansible_tutorial.git
    Cloning into 'ansible_tutorial'...
    remote: Reusing existing pack: 112, done.
    remote: Total 112 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (112/112), 37.58 KiB | 0 bytes/s, done.
    Resolving deltas: 100% (48/48), done.
    Checking connectivity... done.
  2. Make a virtualenv named venv for your Python environment of choice.

    • For Python2:

      $ virtualenv venv
      
    • For Python3:

      $ python3 -m venv venv
      
  3. Activate the Virtual Enviroment. Every time you come back to work on this project, you will need to activate your virtual environment:

    $ cd <full path to this repo>
    $ source venv/bin/activate
    

    When the Virtual Environment is activated, you should see venv in the prompt. It may look something to this:

    (venv) $
    

    (OPTIONAL) I often like to be able to jump to this folder quickly from anywhere and have it automatically setup my virtual environment. So, I put something like this in my $HOME/.bashrc (or equivalent) file:

    function cd_ansible_tutorial {
        deactivate 2> /dev/null
        cd /FULL_PATH_TO_THIS_DIRECTORY
        source venv/bin/activate
    }
  4. Upgrade Pip. The Pip that comes with a new Virtual Environment is often too old. Upgrade it to be sure it is current:

    (venv)$ pip install --upgrade pip
    Collecting pip
      Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
    Installing collected packages: pip
      Found existing installation: pip 9.0.3
        Uninstalling pip-9.0.3:
          Successfully uninstalled pip-9.0.3
    Successfully installed pip-10.0.1
  5. Configure the repo for your account and settings

    (venv)$ ( cd src; python configure.py )
    
    This script creates configuration files for using Ansible to
    configure a newly-created virtual machine.
    It has been tested by the author on an AWS free tier VM.
    This has the best chance of working on an AWS free tier VM, or
    failing that, on a VM with a recent version of CentOS.
    
    No configuration file found. Let me ask questions so that we can configure.
    
    What is the path to your .pem key file for  the virtual machine?
    --> ~/example_key.pem
    
    What user to use to ssh to the remote system [ec2-user]?
    -->
    Configuring `ansible_hosts` file ./ansible_hosts...
    
    What is the IP address of the virtual machine?
    --> demos.glenjarvis.com
    
    Configuration is complete.
  6. Follow the examples (starting with the example_01 subdirectory).

Examples

Here is a list of the examples just in case there's any confusion in which order the examples should be executed:

  1. ( cd src; python configure.py ) (see instructions above)
  2. ( cd src/example_01; python access_machine.py )
  3. ( cd src/example_02; python auto_update_machine.py )
  4. ( cd src/example_03; less README.txt ) (Read the README.txt file; it's not really meant to be executed)
  5. ( cd src/example_04; ansible webservers -m ping; ansible webservers -vvv -m ping )
  6. ( cd src/example_05; ansible webservers -vvv -a 'sudo yum update -y' )
  7. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_01.yml )
  8. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_02.yml )
  9. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_03.yml )
  10. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_04.yml )
  11. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_05.yml )
  12. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_06.yml )
  13. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_07.yml )
  14. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_08.yml )
  15. ( cd src/playbook_examples; ansible-playbook demo_playbook_iter_09.yml )
  16. ( cd src/playbook_examples; less pedantically_commented_playbook ) (Read but don't execute: pedantically_commented_playbook.yml)
  17. ( cd src/role_examples; ansible-playbook demo_play_role_01.yml )
  18. ( cd src/role_examples; ansible-playbook demo_play_role_02.yml )
  19. ( cd src/role_examples; ansible-playbook demo_play_role_03.yml )
  20. Exploration: Log into machine; sudo su - webuser; cd /home/webuser/sample_project; python manage.py runserver

Bio

Glen has been a Python programmer since 2007 and has worked for companies such as IBM, UC Berkeley, Sprint, Informix, and many start-ups. He has also worked both in the US and in the UK and has had Bioinformatics research published in Nucleic Acids Research (Oxford Journals) He is a certified DBA and has also been certified in Linux/Unix Administration.

He is a DevOps engineer and uses Ansible heavily. After five years, he just finished working for a startup. He is creating a Coursera course in collaboration with a UC campus on Source Code Mangement Systems for the DevOps developer.

Additionally, he runs a small start up, Glen Jarvis Training & Consulting, LLC, that does online technical training and assists employees obtaining telepresence in their current work place.

Glen is the organizer for the Silicon Valley Python MeetUp Group and a co-organizer of the Bay Area Python Interest Group.

More information:

Make this better by Contributing

This is an Open Source project and contributions are always welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

To maximize the chance that your hard work gets merged, we have these guidelines to guide you along the way to a successfully merged Pull Request: