Skip to content

Instantly share code, notes, and snippets.

@PaulReiber
Last active May 14, 2019 19:52
Show Gist options
  • Select an option

  • Save PaulReiber/7379894 to your computer and use it in GitHub Desktop.

Select an option

Save PaulReiber/7379894 to your computer and use it in GitHub Desktop.
Run a particular command over all of the cloud servers in your cloud stack. "overstack w" for example.
#!/usr/bin/ruby
#############################################
# Ruby / Fog Cloud Server Command Runner
#
# Author: Paul Reiber [email protected]
# however some parts have been borrowed from basics.rb
#
# Usage: overstack commandline-to-run-on-all-cloud-servers
#
# Note: before you run this the first time, edit the file and fix the example.net stuff below
#
# Assumptions:
# * You are using an OpenStack Cloud
# * your linux account has proper key-based root ssh access to all servers within your cloud.
# ...take steps similar to the following if they don't have ssh key-based access yet:
# http://www.rackspace.com/knowledge_center/article/secure-shell-ssh
#
# The code:
require 'rubygems'
require 'fog'
require 'pp'
require 'oj'
# The 'oj' gem requirement is only there to eliminate the irritating warning about using the default JSON parser
auth_url = "https://example.net/v2.0/tokens"
username = '[email protected]'
password = 'secret'
tenant = 'OpenCloudTenantName' # String
# REPLACE the quoted values above with your username password auth_url and tenant name.
service = Fog::Compute.new({ :provider => :openstack,
:openstack_api_key => password,
:openstack_username => username,
:openstack_auth_url => auth_url ,
:openstack_tenant => tenant })
# running a command on all servers and reporting the results is as simple as the following:
service.servers.each {|n| puts n.name; pp n.ssh [ARGV] }
# thats all it takes!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment