AWS Cloudformation

I wanted to create a very basic, very beginner guide to cloudformation. The information I found on it went 0 to 60 pretty quickly, and I just found myself barely hanging on to understand.

Cloudformation is a way to model an AWS infrastructure in code. This allows for a reasonable way to quickly stand up new environments, ensure state of current environments, or change the state of environments.

I have written a tutorial and provided example templates over at my Github Repo. (Because of the way wordpress formats code snippets, I left all of it over there.)



Ansible Basics



  • copying from cfg file to deploy to the router
  • tasks defined in the main playbook
  • tasks using roles in three different ways
    • tasks defined in the role
    • tasks that import tasks




hostname CSR01

ip domain-name
crypto key generate rsa modulus 2048

snmp-server community publicRO

router ospf 100

interface g1

  description to_Core
  ip address
  ip ospf 100 area 0
  no shutdown

interface g2

  description to_Core
  ip address
  ip ospf 100 area 1
  no shutdown

interface lo1

  description EIGRP RID
  ip address
  ip ospf 100 area 0
  no shutdown



localhost ansible_connection=local


I run the playbook and include the hosts file:

ansible-playbook csr_config.yml -i ./hosts

Here is what the playbook looks like.


- name: Configure a CSR Router
hosts: CSR
username: admin
password: cisco
authorize: yes

- name: apply config file to the router
authorize: yes





- name: Apply Configuration to CSR
hosts: CSR
username: admin
password: cisco

- name: Configure Interface G2
- ip address
- description Configured by Ansible Playbook CSR-Basic
parents: interface g1
- name: Configure NTP
lines: ntp server



├── hosts
├── roles
│   ├── interfaces
│   │   ├── Tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   └── int.j2
│   │   └── vars
│   │   └── main.yml
│   ├── ntp
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   └── ospf
│   ├── tasks
│   │   ├── main.yml
│   │   ├── ospf-int.yml
│   │   └── ospf-proc.yml
│   └── templates
└── site.yml



- name: provide creds
hosts: CSR

- ntp
- ospf
- interfaces


Here is the main.yml file for the ntp role.


- name: set ntp server
- ntp server

It just very simply sets the ntp server.


our main.yml for the OSPF role is as follows.


- import_tasks: ospf-proc.yml
- import_tasks: ospf-int.yml

The ospf-proc.yml sets the process-id and RID.


- name: set ospf process
- router ospf 100

- name: set router id
- router-id
parents: router ospf 100

The ospf-int.yml configures the interface.


- name: set OSPF Interface
- ip ospf 100 area 0
- interface g1



- name: configure interface settings
src: int.j2



{% for interface in %}
interface {{ interface['int'] }}
description {{ interface['description'] }}
no shutdown
{% endfor %}





SSH password:


ok: []

changed: []

changed: []

changed: []

changed: []

changed: []



# uncomment this to disable SSH key host checking
host_key_checking = False


# host key checking setting above.

These files are available on my github repository:

My Vagrant Setup

I’ve seen and heard how Vagrant is powerful tool for development environments. Vagrant is a tool from Hashicorp for managing virtual environments. I’ve had it installed for a while, but never really dug in far enough to understand the value. Well, like most things, I didn’t understand the value because I didn’t have a particular use case. Well now I do…

I was having issues running multiple VMs on my MacBook Pro via Fusion. Namely, that if I want to run a CSR router, I don’t have the horsepower to also run other VMs at the same time. A coworker of mine had mentioned on an internal forum that he recommended using Vagrant for testing Ansible. I am just scratching the surface I believe, but this did solve my particular problem. I can spin up a VM using Vagrant to test my Ansible playbooks against the aforementioned CSR–all on my laptop.

I won’t cover the basic installation of Vagrant itself, but that information is available at the Vagrant website, as well as much more documentation:

OK. So here is where I start customizing. When you install Vagrant, a file named vagrantfile gets installed and contains all the information about your vagrant environment.

If you want to customize the different ansible machines you can spin up, copy the vagrant file into different directory per project.

For mine, I copied the vagrantfile into /vagrant-ansible-example/.

I can now edit the vagrantfile to customize this instance.

I can set which OS to spin up. = "ubuntu/trusty64"

I can create a synced folder. I can have my Ansible files, or python files on my desktop and mount that directory from within the vagrant machine. This is useful to have access to playbooks or scripts that I am editing that I want to run from within a VM.

config.vm.synced_folder "/Users/bob/Documents/Github", "/Github"

I can then customize my vagrant machine by calling a bash startup script to install ansible, pip, and xlrd. (These are just examples, could be any packages you need to install.)

  config.vm.provision "shell" do |s|
    s.path = "./"

Here is a snippet of what my setup script looks like.

<br />#!/bin/bash

echo "setting up environment"
echo "installing ansible"
sudo apt-get install ansible -y
echo "installing pip"
sudo apt-get install python-pip -y
echo "installing xlrd"
sudo pip install xlrd

We spin up or machine from within the Vagrant-ansible-example directory.

vagrant up

It boots up our OS and runs our startup script, then we can ssh to our machine and start testing.

The nice thing about Vagrant, I have found, is I can easily reset my machine back to this first known-good state, or change my startup parameters and spin up a new VM anytime.

I can do this by issuing a vagrant destroy command, which will wipe out any state configuration on my VM. Then I just issue vagrant up again and it spins up my VM like it was a brand new install.