SlideShare a Scribd company logo
Vagrant, Ansible and OpenStack
               on your laptop
                              Lorin Hochstein
                              Nimbis Services


Email: lorin@nimbisservices.com
Twitter: lhochstein
Setting up OpenStack for production is
          complex and error-prone
2012-08-04 12:31:56 INFO nova.rpc.common [-] Reconnecting to AMQP server on localhost:5672
2012-08-04 12:31:56 ERROR nova.rpc.common [-] AMQP server on localhost:5672 is unreachable:
[Errno 111] ECONNREFUSED. Trying again in 30 seconds.
2012-08-04 12:31:56 TRACE nova.rpc.common Traceback (most recent call last):
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/nova/rpc/impl_kombu.py", line 446, in reconnect
2012-08-04 12:31:56 TRACE nova.rpc.common     self._connect()
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/nova/rpc/impl_kombu.py", line 423, in _connect
2012-08-04 12:31:56 TRACE nova.rpc.common     self.connection.connect()
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/kombu/connection.py", line 154, in connect
2012-08-04 12:31:56 TRACE nova.rpc.common     return self.connection
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/kombu/connection.py", line 560, in connection
2012-08-04 12:31:56 TRACE nova.rpc.common     self._connection = self._establish_connection()
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/kombu/connection.py", line 521, in _establish_connection
2012-08-04 12:31:56 TRACE nova.rpc.common     conn = self.transport.establish_connection()
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/kombu/transport/pyamqplib.py", line 255, in establish_connection
2012-08-04 12:31:56 TRACE nova.rpc.common     connect_timeout=conninfo.connect_timeout)
2012-08-04 12:31:56 TRACE nova.rpc.common   File "/usr/lib/python2.7/dist-
packages/kombu/transport/pyamqplib.py", line 52, in __init__
2012-08-04 12:31:56 TRACE nova.rpc.common     super(Connection, self).__init__(*args,
You're looking for better ways to do
            deployment
Shell scripts are painful, Puppet & Chef
           have steep learning curves
if [[ $EUID -eq 0 ]]; then
    ROOTSLEEP=${ROOTSLEEP:-10}
    echo "You are running this script as root."
    echo "In $ROOTSLEEP seconds, we will create a user 'stack' and run as that
user"
    sleep $ROOTSLEEP

    # since this script runs as a normal user, we need to give that user
    # ability to run sudo
    if [[ "$os_PACKAGE" = "deb" ]]; then
        dpkg -l sudo || apt_get update && install_package sudo
    else
        rpm -qa | grep sudo || install_package sudo
    fi
    if ! getent passwd stack >/dev/null; then
        echo "Creating a user called stack"
        useradd -U -s /bin/bash -d $DEST -m stack
    fi




Source: devstack/stack.sh
You want an easy way to write & debug
         deployment scripts
Use Ansible to write OpenStack
deployment scripts, Vagrant to test
       them inside of VMs
Ansible big idea: very simple syntax,
      SSH for communication
Example Ansible play: install ntp
---
- hosts: controller
  tasks:
  - name: ensure ntp packages is installed
    action: apt pkg=ntp

 - name: ensure ntp.conf file is present
   action: copy src=files/ntp.conf dest=/etc/ntp.conf
           owner=root group=root mode=0644

 - name: ensure ntp service is restarted
   action: service name=ntp state=restarted
Specify hosts in an inventory file
[controller]
192.168.206.130

[compute]
192.168.206.131
192.168.206.132
192.168.206.133
192.168.206.134
Run the playbook
$ ansible-playbook ntp.yaml
PLAY [controller] *********************

GATHERING FACTS *********************
ok: [192.168.206.130]

TASK: [ensure ntp packages is installed] *********************
ok: [192.168.206.130]

TASK: [ensure ntp.conf file is present] *********************
ok: [192.168.206.130]

TASK: [ensure ntp service is restarted] *********************
ok: [192.168.206.130]

PLAY RECAP *********************
192.168.206.130     : ok=4    changed=3
                      unreachable=0     failed=0
What did Ansible just do?
1. Made SSH connections to remote host
2. Copied over Python modules and arguments
   parsed from playbook file
3. Executed modules on remote machine
Can run a single action using
          ansible command
$ ansible controller –m apt –a "pkg=ntp"

192.168.206.130 | success >> {
    "changed": false,
    "item": "",
    "module": "apt"
}
Ansible scripts are idempotent: can
        run multiple times safely
$ ansible-playbook ntp.yaml
PLAY [controller] *********************

GATHERING FACTS *********************
ok: [192.168.206.130]

TASK: [ensure ntp packages is installed]
*********************
ok: [192.168.206.130]

TASK: [ensure ntp.conf file is present] *********************
ok: [192.168.206.130]

TASK: [ensure ntp service is restarted] *********************
ok: [192.168.206.130]

PLAY RECAP *********************
192.168.206.130     : ok=4    changed=1
                      unreachable=0     failed=0
Use handlers if action should only
          occur on a state change
---
- hosts: controller
  tasks:
  - name: ensure glance database is present
    action: mysql_db name=glance
    notify:
    - version glance database

 handlers:
 - name: version glance database
   action: command glance-manage version_control 0
Use templates to substitute variables
            in config file
keystone.conf:
[DEFAULT]
public_port = 5000
admin_port = 35357
admin_token = {{ admin_token }}

keystone.yaml:
hosts: controller
vars:
   admin_token: 012345SECRET99TOKEN012345
tasks:
 - name: ensure keystone config script is present
    action: template src=keystone.conf dest=/etc/keystone/
               keystone.conf owner=root group=root mode=0644
Ansible supports multiple modules,
    can also do arbitrary shell commands
•   apt & yum packages
•   Stop/start/restart services
•   users & groups
•   Add SSH public keys
•   MySQL & PostgreSQL users & databases
•   VMs managed by libvirt
•   Git checkouts
Vagrant big idea: redistributable VMs,
  run with config files & commands
Import a new virtual machine
       (Ubuntu 12.04 64-bit)

$ vagrant box add precise64
http://files.vagrantup.com/
       precise64.box
Make a Vagrantfile


Vagrant::Config.run do |config|
  config.vm.box = "precise64"
end



    Vagrant can also generate this for you: “vagrant init precise64”
Boot it and connect to it
$ vagrant   up
[default]   Importing base box 'precise64'...
[default]   Matching MAC address for NAT networking...
[default]   Clearing any previously set forwarded ports...
[default]   Fixed port collision for 22 => 2222. Now on port 2200.
[default]   Forwarding ports...
[default]   -- 22 => 2200 (adapter 1)
[default]   Creating shared folders metadata...
[default]   Clearing any previously set network interfaces...
[default]   Booting VM...
[default]   Waiting for VM to boot. This can take a few minutes.
[default]   VM booted and ready for use!
[default]   Mounting shared folders...
[default]   -- v-root: /vagrant

$ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Thu Jun 7 00:49:30 2012 from 10.0.2.2
vagrant@precise64:~$
Boot multi-VMs: configure IPs,
            memory, hostname
Vagrant::Config.run do |config|

 config.vm.box = "precise64”
 config.vm.define :controller do |controller_config|
   controller_config.vm.network :hostonly, "192.168.206.130"
   controller_config.vm.host_name = "controller"
 end

 config.vm.define :compute1 do |compute1_config|
   compute1_config.vm.network :hostonly, "192.168.206.131"
   compute1_config.vm.host_name = "compute1"
   compute1_config.vm.customize ["modifyvm", :id,
                                 "--memory", 1024]
 end

end
Openstack-ansible: Ansible scripts for
       OpenStack Compute




                     Links to OpenStack
                     Install & Deploy Guide
Config: controller, one compute host,
          QEMU, FlatDHCP

     controller                                          compute1

                         .130              .131
                  eth1                            eth1
                                192.168.206.*




                         .130              .131
                  eth2                            eth2
    eth0                        192.168.100.*              eth0

    NAT                                                    NAT
Vagrantfile describes this setup
Vagrant::Config.run do |config|

 config.vm.box = "precise64"

 config.vm.define :controller do |controller_config|
   controller_config.vm.network :hostonly, "192.168.206.130”
   controller_config.vm.host_name = "controller"
 end

  config.vm.define :compute1 do |compute1_config|
    compute1_config.vm.network :hostonly, "192.168.206.131”
    compute1_config.vm.host_name = "compute1"
    compute1_config.vm.customize ["modifyvm", :id, "--memory",
1024]
    compute1_config.vm.customize ["modifyvm", :id, "--
nicpromisc3",
                              "allow-all"]
  end
end
If all goes well…
$ make all
. . .
-------------------------------------+--------------------------------------+
| Property                            | Value                                 |
+-------------------------------------+--------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                |
| OS-EXT-SRV-ATTR:host                | None                                  |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                  |
| OS-EXT-SRV-ATTR:instance_name       | instance-00000001                     |
| OS-EXT-STS:power_state              | 0                                     |
| OS-EXT-STS:task_state               | scheduling                            |
| OS-EXT-STS:vm_state                 | building                              |
| accessIPv4                          |                                       |
| accessIPv6                          |                                       |
| adminPass                           | CJ8NNNa4dc6f                          |
| config_drive                        |                                       |
| created                             | 2012-08-09T02:51:14Z                  |
| flavor                              | m1.tiny                               |
| hostId                              |                                       |
| id                                  | 8e9238b8-208d-46a8-8f66-c40660abacff |
| image                               | cirros-0.3.0-x86_64                   |
| key_name                            | mykey                                 |
| metadata                            | {}                                    |
| name                                | cirros                                |
Links
• Vagrantfile & Ansible playbooks for OpenStack:
http://github.com/lorin/openstack-ansible
• Ansible: http://ansible.github.com
• Vagrant: http://vagrantup.com
• Ansible playbook examples:
  https://github.com/ansible/ansible/tree/devel/examples
  /playbooks
• Vagrant boxes: http://vagrantbox.es
Image sources
•   http://vagrantup.com
•   http://ansible.github.com
•   http://openstack.org
•   http://en.wikipedia.org/wiki/File:Rack001.jpg
•   http://en.wikipedia.org/wiki/File:Easy_button.JPG
•   http://hezik.nl/enable-ssh-server-on-backtrack-5-r2/

More Related Content

What's hot (20)

PDF
Storage 101: Rook and Ceph - Open Infrastructure Denver 2019
Sean Cohen
 
PPTX
iostat await svctm の 見かた、考え方
歩 柴田
 
PDF
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
Shinya Sugiyama
 
PDF
DevOps Meetup ansible
sriram_rajan
 
PPTX
Molecule入門
Hiroki Uchida
 
PPTX
Automating with Ansible
Ricardo Schmidt
 
PDF
Red Hat OpenStack - Open Cloud Infrastructure
Alex Baretto
 
PPTX
Hadoop Meetup Jan 2019 - Overview of Ozone
Erik Krogen
 
PDF
Rancher/Kubernetes入門ハンズオン資料~第2回さくらとコンテナの夕べ #さくらの夕べ 番外編
Masahito Zembutsu
 
ODP
ansible why ?
Yashar Esmaildokht
 
PDF
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
OpenStack Korea Community
 
PPTX
Anthos を使ったエンタープライズ向けクラスタの設計とアップグレード戦略のススメ(CloudNative Days Tokyo 2021 発表資料)
NTT DATA Technology & Innovation
 
PPTX
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
NTT DATA Technology & Innovation
 
PDF
Dockerfileを改善するためのBest Practice 2019年版
Masahito Zembutsu
 
PDF
DevOps with Ansible
Swapnil Jain
 
PDF
「Neutronになって理解するOpenStack Network」~Neutron/Open vSwitchなどNeutronと周辺技術の解説~ - ...
VirtualTech Japan Inc.
 
PPTX
Ansible presentation
Suresh Kumar
 
PDF
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
NTT DATA Technology & Innovation
 
PPTX
Apache Spark on Kubernetes入門(Open Source Conference 2021 Online Hiroshima 発表資料)
NTT DATA Technology & Innovation
 
Storage 101: Rook and Ceph - Open Infrastructure Denver 2019
Sean Cohen
 
iostat await svctm の 見かた、考え方
歩 柴田
 
MySQL InnoDB Clusterによる高可用性構成(DB Tech Showcase 2017)
Shinya Sugiyama
 
DevOps Meetup ansible
sriram_rajan
 
Molecule入門
Hiroki Uchida
 
Automating with Ansible
Ricardo Schmidt
 
Red Hat OpenStack - Open Cloud Infrastructure
Alex Baretto
 
Hadoop Meetup Jan 2019 - Overview of Ozone
Erik Krogen
 
Rancher/Kubernetes入門ハンズオン資料~第2回さくらとコンテナの夕べ #さくらの夕べ 番外編
Masahito Zembutsu
 
ansible why ?
Yashar Esmaildokht
 
[OpenInfra Days Korea 2018] Day 2 - CEPH 운영자를 위한 Object Storage Performance T...
OpenStack Korea Community
 
Anthos を使ったエンタープライズ向けクラスタの設計とアップグレード戦略のススメ(CloudNative Days Tokyo 2021 発表資料)
NTT DATA Technology & Innovation
 
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
NTT DATA Technology & Innovation
 
Dockerfileを改善するためのBest Practice 2019年版
Masahito Zembutsu
 
DevOps with Ansible
Swapnil Jain
 
「Neutronになって理解するOpenStack Network」~Neutron/Open vSwitchなどNeutronと周辺技術の解説~ - ...
VirtualTech Japan Inc.
 
Ansible presentation
Suresh Kumar
 
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
NTT DATA Technology & Innovation
 
Apache Spark on Kubernetes入門(Open Source Conference 2021 Online Hiroshima 発表資料)
NTT DATA Technology & Innovation
 

Viewers also liked (20)

PDF
OpenStack Deployment in the Enterprise
Cisco Canada
 
PPTX
Deploying OpenStack with Ansible
Kevin Carter
 
PDF
[1A7]Ansible의이해와활용
NAVER D2
 
PDF
OpenStack Branding and Marketing
Open Stack
 
PPTX
Quantum essex summary
Dan Wendlandt
 
KEY
ZeroMQ简介
Xu Wang
 
PDF
Nosql why and how on Microsoft Azure
Vito Flavio Lorusso
 
PDF
Dough: OpenStack Billing Project
Zhongyue Luo
 
PPTX
Winning at Personalized Customer Engagement
Marketo
 
PDF
OpenStack design summit (colony session)
Shigetoshi Yokoyama
 
PDF
Securing open stack for compliance
Tomasz Zen Napierala
 
ODP
Ansible & Vagrant
Mukul Malhotra
 
PDF
Flexible, simple deployments with OpenStack-Ansible
Major Hayden
 
PDF
Managing sensitive data with Ansible vault
Pascal Stauffer
 
PPTX
Ansible for Enterprise
Ansible
 
PPTX
[세미나] Vagrant 이지원
지원 이
 
PDF
OpenStack-Ansible Security
Major Hayden
 
PDF
XE 모듈 개발 - 걸음마부터 날기까지 - 달리기
승엽 신
 
PPTX
Deploying Efficient OpenStack Clouds, Yaron Haviv
Cloud Native Day Tel Aviv
 
PPTX
Open stack and sdn hands-on and demo
Kyohei Moriyama
 
OpenStack Deployment in the Enterprise
Cisco Canada
 
Deploying OpenStack with Ansible
Kevin Carter
 
[1A7]Ansible의이해와활용
NAVER D2
 
OpenStack Branding and Marketing
Open Stack
 
Quantum essex summary
Dan Wendlandt
 
ZeroMQ简介
Xu Wang
 
Nosql why and how on Microsoft Azure
Vito Flavio Lorusso
 
Dough: OpenStack Billing Project
Zhongyue Luo
 
Winning at Personalized Customer Engagement
Marketo
 
OpenStack design summit (colony session)
Shigetoshi Yokoyama
 
Securing open stack for compliance
Tomasz Zen Napierala
 
Ansible & Vagrant
Mukul Malhotra
 
Flexible, simple deployments with OpenStack-Ansible
Major Hayden
 
Managing sensitive data with Ansible vault
Pascal Stauffer
 
Ansible for Enterprise
Ansible
 
[세미나] Vagrant 이지원
지원 이
 
OpenStack-Ansible Security
Major Hayden
 
XE 모듈 개발 - 걸음마부터 날기까지 - 달리기
승엽 신
 
Deploying Efficient OpenStack Clouds, Yaron Haviv
Cloud Native Day Tel Aviv
 
Open stack and sdn hands-on and demo
Kyohei Moriyama
 
Ad

Similar to Vagrant, Ansible, and OpenStack on your laptop (20)

PPTX
Openstack Quantum + Devstack Tutorial
David Lapsley
 
PDF
Openstack 101
POSSCON
 
PDF
Troubleshooting vm's presen
kiwimjg
 
PDF
Open stack pike-devstack-tutorial
Eueung Mulyana
 
PDF
NetDevOps Developer Environments with Vagrant @ SCALE16x
Hank Preston
 
PPTX
OpenStack Development Using devstack
mestery
 
PDF
Azure VM base images with Packer, Ansble and Vagrant
Bas Meijer
 
PDF
FreeBSD: Dev to Prod
Sean Chittenden
 
PDF
Making environment for_infrastructure_as_code
Soshi Nemoto
 
TXT
Havana版 RDO-QuickStart-3 Answer File(RDO-QuickStart-3.txt)
VirtualTech Japan Inc.
 
PDF
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
維泰 蔡
 
TXT
Havana版 RDO-QuickStart-2 Answer File(answer2.txt)
VirtualTech Japan Inc.
 
TXT
Havana版 RDO-QuickStart-1 Answer File(answer1.txt)
VirtualTech Japan Inc.
 
ODP
Triangle OpenStack meetup 09 2013
Dan Radez
 
PDF
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
George Boobyer
 
PDF
Open nebula froscon
OpenNebula Project
 
PDF
Vagrant - Version control your dev environment
bocribbz
 
PDF
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
PDF
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
NETWAYS
 
PPTX
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Trevor Roberts Jr.
 
Openstack Quantum + Devstack Tutorial
David Lapsley
 
Openstack 101
POSSCON
 
Troubleshooting vm's presen
kiwimjg
 
Open stack pike-devstack-tutorial
Eueung Mulyana
 
NetDevOps Developer Environments with Vagrant @ SCALE16x
Hank Preston
 
OpenStack Development Using devstack
mestery
 
Azure VM base images with Packer, Ansble and Vagrant
Bas Meijer
 
FreeBSD: Dev to Prod
Sean Chittenden
 
Making environment for_infrastructure_as_code
Soshi Nemoto
 
Havana版 RDO-QuickStart-3 Answer File(RDO-QuickStart-3.txt)
VirtualTech Japan Inc.
 
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
維泰 蔡
 
Havana版 RDO-QuickStart-2 Answer File(answer2.txt)
VirtualTech Japan Inc.
 
Havana版 RDO-QuickStart-1 Answer File(answer1.txt)
VirtualTech Japan Inc.
 
Triangle OpenStack meetup 09 2013
Dan Radez
 
Drupal Camp Brighton 2015: Ansible Drupal Medicine show
George Boobyer
 
Open nebula froscon
OpenNebula Project
 
Vagrant - Version control your dev environment
bocribbz
 
Bare Metal to OpenStack with Razor and Chef
Matt Ray
 
OSDC 2013 | Ansible: configuration management doesn't have to be complicated ...
NETWAYS
 
Couch to OpenStack: Neutron (Quantum) - August 13, 2013 Featuring Sean Winn
Trevor Roberts Jr.
 
Ad

Recently uploaded (20)

PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 

Vagrant, Ansible, and OpenStack on your laptop

  • 1. Vagrant, Ansible and OpenStack on your laptop Lorin Hochstein Nimbis Services Email: lorin@nimbisservices.com Twitter: lhochstein
  • 2. Setting up OpenStack for production is complex and error-prone 2012-08-04 12:31:56 INFO nova.rpc.common [-] Reconnecting to AMQP server on localhost:5672 2012-08-04 12:31:56 ERROR nova.rpc.common [-] AMQP server on localhost:5672 is unreachable: [Errno 111] ECONNREFUSED. Trying again in 30 seconds. 2012-08-04 12:31:56 TRACE nova.rpc.common Traceback (most recent call last): 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/nova/rpc/impl_kombu.py", line 446, in reconnect 2012-08-04 12:31:56 TRACE nova.rpc.common self._connect() 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/nova/rpc/impl_kombu.py", line 423, in _connect 2012-08-04 12:31:56 TRACE nova.rpc.common self.connection.connect() 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/kombu/connection.py", line 154, in connect 2012-08-04 12:31:56 TRACE nova.rpc.common return self.connection 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/kombu/connection.py", line 560, in connection 2012-08-04 12:31:56 TRACE nova.rpc.common self._connection = self._establish_connection() 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/kombu/connection.py", line 521, in _establish_connection 2012-08-04 12:31:56 TRACE nova.rpc.common conn = self.transport.establish_connection() 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/kombu/transport/pyamqplib.py", line 255, in establish_connection 2012-08-04 12:31:56 TRACE nova.rpc.common connect_timeout=conninfo.connect_timeout) 2012-08-04 12:31:56 TRACE nova.rpc.common File "/usr/lib/python2.7/dist- packages/kombu/transport/pyamqplib.py", line 52, in __init__ 2012-08-04 12:31:56 TRACE nova.rpc.common super(Connection, self).__init__(*args,
  • 3. You're looking for better ways to do deployment
  • 4. Shell scripts are painful, Puppet & Chef have steep learning curves if [[ $EUID -eq 0 ]]; then ROOTSLEEP=${ROOTSLEEP:-10} echo "You are running this script as root." echo "In $ROOTSLEEP seconds, we will create a user 'stack' and run as that user" sleep $ROOTSLEEP # since this script runs as a normal user, we need to give that user # ability to run sudo if [[ "$os_PACKAGE" = "deb" ]]; then dpkg -l sudo || apt_get update && install_package sudo else rpm -qa | grep sudo || install_package sudo fi if ! getent passwd stack >/dev/null; then echo "Creating a user called stack" useradd -U -s /bin/bash -d $DEST -m stack fi Source: devstack/stack.sh
  • 5. You want an easy way to write & debug deployment scripts
  • 6. Use Ansible to write OpenStack deployment scripts, Vagrant to test them inside of VMs
  • 7. Ansible big idea: very simple syntax, SSH for communication
  • 8. Example Ansible play: install ntp --- - hosts: controller tasks: - name: ensure ntp packages is installed action: apt pkg=ntp - name: ensure ntp.conf file is present action: copy src=files/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=0644 - name: ensure ntp service is restarted action: service name=ntp state=restarted
  • 9. Specify hosts in an inventory file [controller] 192.168.206.130 [compute] 192.168.206.131 192.168.206.132 192.168.206.133 192.168.206.134
  • 10. Run the playbook $ ansible-playbook ntp.yaml PLAY [controller] ********************* GATHERING FACTS ********************* ok: [192.168.206.130] TASK: [ensure ntp packages is installed] ********************* ok: [192.168.206.130] TASK: [ensure ntp.conf file is present] ********************* ok: [192.168.206.130] TASK: [ensure ntp service is restarted] ********************* ok: [192.168.206.130] PLAY RECAP ********************* 192.168.206.130 : ok=4 changed=3 unreachable=0 failed=0
  • 11. What did Ansible just do? 1. Made SSH connections to remote host 2. Copied over Python modules and arguments parsed from playbook file 3. Executed modules on remote machine
  • 12. Can run a single action using ansible command $ ansible controller –m apt –a "pkg=ntp" 192.168.206.130 | success >> { "changed": false, "item": "", "module": "apt" }
  • 13. Ansible scripts are idempotent: can run multiple times safely $ ansible-playbook ntp.yaml PLAY [controller] ********************* GATHERING FACTS ********************* ok: [192.168.206.130] TASK: [ensure ntp packages is installed] ********************* ok: [192.168.206.130] TASK: [ensure ntp.conf file is present] ********************* ok: [192.168.206.130] TASK: [ensure ntp service is restarted] ********************* ok: [192.168.206.130] PLAY RECAP ********************* 192.168.206.130 : ok=4 changed=1 unreachable=0 failed=0
  • 14. Use handlers if action should only occur on a state change --- - hosts: controller tasks: - name: ensure glance database is present action: mysql_db name=glance notify: - version glance database handlers: - name: version glance database action: command glance-manage version_control 0
  • 15. Use templates to substitute variables in config file keystone.conf: [DEFAULT] public_port = 5000 admin_port = 35357 admin_token = {{ admin_token }} keystone.yaml: hosts: controller vars: admin_token: 012345SECRET99TOKEN012345 tasks: - name: ensure keystone config script is present action: template src=keystone.conf dest=/etc/keystone/ keystone.conf owner=root group=root mode=0644
  • 16. Ansible supports multiple modules, can also do arbitrary shell commands • apt & yum packages • Stop/start/restart services • users & groups • Add SSH public keys • MySQL & PostgreSQL users & databases • VMs managed by libvirt • Git checkouts
  • 17. Vagrant big idea: redistributable VMs, run with config files & commands
  • 18. Import a new virtual machine (Ubuntu 12.04 64-bit) $ vagrant box add precise64 http://files.vagrantup.com/ precise64.box
  • 19. Make a Vagrantfile Vagrant::Config.run do |config| config.vm.box = "precise64" end Vagrant can also generate this for you: “vagrant init precise64”
  • 20. Boot it and connect to it $ vagrant up [default] Importing base box 'precise64'... [default] Matching MAC address for NAT networking... [default] Clearing any previously set forwarded ports... [default] Fixed port collision for 22 => 2222. Now on port 2200. [default] Forwarding ports... [default] -- 22 => 2200 (adapter 1) [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] Mounting shared folders... [default] -- v-root: /vagrant $ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Thu Jun 7 00:49:30 2012 from 10.0.2.2 vagrant@precise64:~$
  • 21. Boot multi-VMs: configure IPs, memory, hostname Vagrant::Config.run do |config| config.vm.box = "precise64” config.vm.define :controller do |controller_config| controller_config.vm.network :hostonly, "192.168.206.130" controller_config.vm.host_name = "controller" end config.vm.define :compute1 do |compute1_config| compute1_config.vm.network :hostonly, "192.168.206.131" compute1_config.vm.host_name = "compute1" compute1_config.vm.customize ["modifyvm", :id, "--memory", 1024] end end
  • 22. Openstack-ansible: Ansible scripts for OpenStack Compute Links to OpenStack Install & Deploy Guide
  • 23. Config: controller, one compute host, QEMU, FlatDHCP controller compute1 .130 .131 eth1 eth1 192.168.206.* .130 .131 eth2 eth2 eth0 192.168.100.* eth0 NAT NAT
  • 24. Vagrantfile describes this setup Vagrant::Config.run do |config| config.vm.box = "precise64" config.vm.define :controller do |controller_config| controller_config.vm.network :hostonly, "192.168.206.130” controller_config.vm.host_name = "controller" end config.vm.define :compute1 do |compute1_config| compute1_config.vm.network :hostonly, "192.168.206.131” compute1_config.vm.host_name = "compute1" compute1_config.vm.customize ["modifyvm", :id, "--memory", 1024] compute1_config.vm.customize ["modifyvm", :id, "-- nicpromisc3", "allow-all"] end end
  • 25. If all goes well… $ make all . . . -------------------------------------+--------------------------------------+ | Property | Value | +-------------------------------------+--------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-SRV-ATTR:host | None | | OS-EXT-SRV-ATTR:hypervisor_hostname | None | | OS-EXT-SRV-ATTR:instance_name | instance-00000001 | | OS-EXT-STS:power_state | 0 | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | accessIPv4 | | | accessIPv6 | | | adminPass | CJ8NNNa4dc6f | | config_drive | | | created | 2012-08-09T02:51:14Z | | flavor | m1.tiny | | hostId | | | id | 8e9238b8-208d-46a8-8f66-c40660abacff | | image | cirros-0.3.0-x86_64 | | key_name | mykey | | metadata | {} | | name | cirros |
  • 26. Links • Vagrantfile & Ansible playbooks for OpenStack: http://github.com/lorin/openstack-ansible • Ansible: http://ansible.github.com • Vagrant: http://vagrantup.com • Ansible playbook examples: https://github.com/ansible/ansible/tree/devel/examples /playbooks • Vagrant boxes: http://vagrantbox.es
  • 27. Image sources • http://vagrantup.com • http://ansible.github.com • http://openstack.org • http://en.wikipedia.org/wiki/File:Rack001.jpg • http://en.wikipedia.org/wiki/File:Easy_button.JPG • http://hezik.nl/enable-ssh-server-on-backtrack-5-r2/

Editor's Notes

  • #9: Ansible scripts are called playbooks, that are organized into individual plays.Ansible plays are collection of tasks. You also need to specify which hosts you’re running on.This play has three tasks: - Install the NTP package - Copy over a local ntp.conf file - Restart the ntp service
  • #10: By default, ansible will look in /etc/ansible/hosts for the inventory file, you can override this to specify a different location.
  • #14: The items that appear in green did not change state. With a real ansible run, yellow ones would change state.
  • #15: Ansible scripts are called playbooks, that are organized into individual plays.Ansible plays are collection of tasks. You also need to specify which hosts you’re running on.This play has three tasks: - Install the NTP package - Copy over a local ntp.conf file - Restart the ntp service
  • #17: Arbitrary shell commands are not idempotent, of course
  • #19: This will download a “box”, a preconfigured
  • #20: This is a bare-bones config file