Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automated DevStack deployments on Rackspace with salt-cloud

Automated DevStack deployments on Rackspace with salt-cloud

Preparation

Install salt-master and salt-cloud

These instructions will install salt-master and salt-cloud on recent Ubuntu releases. Consult the SaltStack Installation Documentation should you require instructions for other distributions.

echo deb http://ppa.launchpad.net/saltstack/salt/ubuntu `lsb_release -sc` main | sudo tee /etc/apt/sources.list.d/saltstack.list
wget -q -O- "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4759FA960E27C0A6" | sudo apt-key add -
sudo apt-get update && sudo apt-get install salt-master python-pip sshpass
pip install salt-cloud

NOTE: Due to a number of improvements in the latest version, this document was written for salt-cloud v0.8.8, so we're installing from pip as opposed to the SaltStack repositories.

Configure salt-cloud

Add Rackspace as a Cloud Provider

In order to build instances, we'll need to make salt-cloud aware of our Cloud account credentials. In this example, I'll be configuring salt-cloud to use Rackspace, though these configurations should be very similar for any OpenStack deployment. This part assumes that you have the common OpenStack environment variables (e.g. $OS_USERNAME) exported in your current environment, as well as $SALT_MASTER_IP, which is the IP address which the minions will use to access your Salt master. If you can't be bothered to export these environment variables yourself, you can just edit the file /etc/salt/cloud.providers by hand afterward.

cat > /etc/salt/cloud.providers <<EOF
rackspace:
  minion:
    master: $SALT_MASTER_IP

  identity_url: "$OS_AUTH_URL"
  compute_name: $OS_SERVICE_NAME
  protocol: ipv4

  compute_region: $OS_REGION_NAME

  user: $OS_USERNAME
  tenant: $OS_TENANT_NAME
  apikey: $OS_PASSWORD

  provider: openstack
EOF

Create base profiles

Now, we're going to create a list of base profiles for salt-cloud to use. This just maps names to instance flavor/image pairings. For example, using the profile precise_512 will boot a 512MB Ubuntu Precise (12.04) instance. The configuration file below provides similar mappings for all flavors of Ubuntu Precise and CentOS 6.3, to which you may add any additional profiles which you'd like to use.

cat > /etc/salt/cloud.profiles <<EOF
### Ubuntu Precise (12.04) ###

precise_512:
  provider: rackspace
  size: 512MB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_1:
  provider: rackspace
  size: 1GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_2:
  provider: rackspace
  size: 2GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_4:
  provider: rackspace
  size: 4GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_8:
  provider: rackspace
  size: 8GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_15:
  provider: rackspace
  size: 15GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

precise_30:
  provider: rackspace
  size: 30GB Standard Instance
  image: e4dbdba7-b2a4-4ee5-8e8f-4595b6d694ce

### CentOS 6.3 ###

cent63_512:
  provider: rackspace
  size: 512MB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_1:
  provider: rackspace
  size: 1GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_2:
  provider: rackspace
  size: 2GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_4:
  provider: rackspace
  size: 4GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_8:
  provider: rackspace
  size: 8GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_15:
  provider: rackspace
  size: 15GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07

cent63_30:
  provider: rackspace
  size: 30GB Standard Instance
  image: da1f0392-8c64-468f-a839-a9e56caebf07
EOF

Final salt-cloud configs

cat > /etc/salt/cloud <<EOF
# Retrieve and execute state data from the master upon booting an instance
start_action: state.highstate
EOF

Configure salt-master

Create states for Devstack deployment

This is where the magic happens. States are the configuration management system which powers SaltStack. They are represented by flat files under /srv/salt (by default), and tell the salt-minion what its desired state is.

export SALT_STATE_DIR=/srv/salt
export DEVSTACK_STATE_DIR=${SALT_STATE_DIR}/devstack
mkdir -p $DEVSTACK_STATE_DIR
cat > ${SALT_STATE_DIR}/top.sls <<EOF
base:
  'devstack.*':
    - devstack
  'devstack.compute*':
    - devstack.compute
  'devstack.controller*':
    - devstack.controller
EOF

cat > ${DEVSTACK_STATE_DIR}/init.sls <<EOF
git:
  pkg.installed

stack:
  group:
    - present
  user.present:
    - fullname: DevStack User
    - shell: /bin/bash
    - home: /opt/stack
    - groups:
        - stack
    - require:
        - group: stack

/opt/stack/localrc:
  file.managed:
    - source: salt://devstack/localrc.j2
    - user: stack
    - group: stack
    - mode: 644
    - template: jinja
    - defaults:
        branch: {{ salt['pillar.get']('branch', 'stable/grizzly') }}
    - require:
        - git: https://github.com/openstack-dev/devstack.git
 
devstack:
  git.latest:
    - name: https://github.com/openstack-dev/devstack.git
    - rev: master
    - target: /opt/stack
    - force: True
    - require:
      - user: stack
      - pkg: git
  file.managed:
    - name: /etc/sudoers.d/50_devstack
    - source: salt://devstack/devstack.sudoers
    - mode: 440
  cmd.run:
    - name: /opt/stack/stack.sh
    - user: stack
    - group: stack
    - shell: /bin/bash
    - require:
        - file: /opt/stack/localrc
        - file: /etc/sudoers.d/50_devstack
        - user: stack
EOF

cat > ${DEVSTACK_STATE_DIR}/localrc.j2 <<EOF
DATABASE_PASSWORD=G2WuzaYU6uDR8dew
RABBIT_PASSWORD=ch2P9AYadRunarUx
SERVICE_TOKEN=9U4uWucr8C8trurU9U4uWucr8C8trurU
SERVICE_PASSWORD=zarE4usE3ukuWEPh
ADMIN_PASSWORD=Y2CUDRethEcacAwr

GLANCE_BRANCH={{ branch }}
HORIZON_BRANCH={{ branch }}
KEYSTONE_BRANCH={{ branch }}
NOVA_BRANCH={{ branch }}
GLANCE_BRANCH={{ branch }}
QUANTUM_BRANCH={{ branch }}

RECLONE=yes
EOF

cat > ${DEVSTACK_STATE_DIR}/devstack.sudoers <<EOF
stack ALL=(ALL) NOPASSWD:ALL
EOF

Create Salt Pillars

Pillars are SaltStack's way of sharing information between minions and states. Pillars are stored under /srv/pillar on the master by default, though you can change that location in /etc/salt/master as needed. If you're coming from the Chef world, they closely resemble node attributes. This is a pretty trivial usage of Pillars, but all we're doing is setting the OpenStack branch so there's no need to get too creative here.

export PILLAR_DIR=/srv/pillar
export DEVSTACK_PILLARS=${PILLAR_DIR}/devstack
mkdir -p ${DEVSTACK_PILLARS}
cat > ${PILLAR_DIR}/top.sls <<EOF
base:
  '*.folsom.*':
    - devstack.folsom
EOF

cat > ${DEVSTACK_PILLARS}/folsom.sls <<EOF
branch: "stable/folsom"
EOF

cat > ${DEVSTACK_PILLARS}/grizzly.sls <<EOF
branch: "stable/grizzly"
EOF

In the end, these Pillars will allow you to build a specific version of OpenStack based on the minion name. More on this below.

Booting a DevStack server

We're finally ready to create our first DevStack server using salt-cloud. Fortunately, thanks to SaltStack, this should be the easy part. Let's create a 15GB Ubuntu Precise server running OpenStack Grizzly:

salt-cloud -p precise_15 devstack.aio

Similarly, we can create a 30GB Ubuntu Precise server running OpenStack Folsom:

salt-cloud -p precise_30 devstack.folsom.aio

Don't be alarmed if the salt-cloud run takes upwards of 20 minutes to complete, this is absolutely normal. When the run is complete, salt-cloud will output all information from the run, including your Horizon login info and data about the instance itself.

Doing more with salt-cloud

Query node information

You can use salt-cloud to list information about your running Cloud instances using the -Q flag:

$ salt-cloud -Q
[INFO    ] Configuration file path: /etc/salt/cloud
[INFO    ] salt-cloud starting

openstack:
    ----------
    devstack.folsom.aio:
        ----------
        id:
            f86e0eba-1735-dead-beef-28960ae899b6
        image:
            None
        private_ips:
            - <SANITIZED>
        public_ips:
            - <SANITIZED>
            - <SANITIZED>
        size:
            None
        state:
            RUNNING
    devstack.grizzly.aio:
        ----------
        id:
            98f56172-d5a8-dead-beef-19e1aa0ec789
        image:
            None
        private_ips:
            - <SANITIZED>
        public_ips:
            - <SANITIZED>
            - <SANITIZED>
        size:
            None
        state:
            RUNNING

Maps

TODO(dw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.