Thursday 1 October 2015

Getting Started With Ansible and Rackspace P2

Introduction
In this post a simple playbook is demonstrated to provision a pseudo DC in Rackspace.

Following on from the previous post, a parametrised playbook is created to:
  •  Install a keypair from a file
  •  create a management network
  •  create a domain name
This playbook will likely only be run once

Create Datacenter Playbook (rs_create_dc.yml)
---
# rs_create_dc.yml

- name: Create Rackspace DC
  hosts: localhost
  connection: local
  gather_facts: false

  vars:
    - region: LON
    - management_net_cidr: 10.45.45.0/24
    - domain_contact: dns@{{ domain_name }}

  tasks:
    - name: Create KeyPair
      rax_keypair:
        name: rs_kp
        region: "{{ region }}"
        public_key: "{{ ssh_key }}"

    - name: Create Management Network
      rax_network:
        label: management
        cidr: "{{ management_net_cidr }}"
        region: "{{ region }}"

    - name: Add Domain Name
      rax_dns:
        name: "{{ domain_name }}"
        email: "{{ domain_contact }}"
        region: "{{ region }}"


The playbook might then be run like this:
ansible-playbook rs_create_dc.yml -e "ssh_key=/home/user/.ssh/publickey.pub domain_name=example.com"