Giter VIP home page Giter VIP logo

cast's Introduction

Cast

This is a Ruby gem that executes remote commands via ssh on groups of servers defined in a YAML file.

Setup

Grab the gem:

gem install cast-ssh

Create your group file at ~/.cast.yml, like this:

group1:
- host1
- host2
- host3

group2:
- host1
- host4
- host5

Run commands in your shell using this pattern:

cast [<flags>] <target> <command>

For example:

cast group1 echo test
cast group1,group2 sudo whoami
cast -s group1,host4 "df -h"

The output from the second command will look something like this:

[cast] loading groups from ~/.cast.yml
[cast] running ssh host1 'sudo whoami'
[cast] running ssh host2 'sudo whoami'
[cast] running ssh host3 'sudo whoami'
[cast] running ssh host4 'sudo whoami'
[host3] root
[host1] root
[host2] root
[host4] root

Note that the commands are run in parallel, so the output may be out of order.

Options

       --serial, -s:   Execute commands serially, rather than in parallel over the group
    --delay, -d <f>:   Delay in seconds between execution of serial commands (switches to serial mode if defined)
--groupfile, -g <s>:   YAML file of server groups (default: ~/.cast.yml)
         --list, -l:   Print out contents of groupfile without executing command
     --clusters, -c:   Print out only groupnames without executing command
      --ssh, -h <s>:   SSH command to run (default: ssh)
      --version, -v:   Print version and exit
         --help, -e:   Show this message

API

You can also access the same functionality from within Ruby.

To include Cast in your code do:

require 'cast'

The following methods are available:

  • Cast::remote host, cmd

    Run a remote command on the given host, sending output to stdout.

  • Cast::local cmd, options = {} -> int

    Run a command locally, printing stdout and stderr from the command. Returns the process' return value.

    You can use the following options:

    :ensure              - Raise exceptions if the command returns a non-zero error code.
    :prefix              - Prefix to use on lines when printing stdout/stderr.
    :clean_bundler_env   - Use a clean bundler environment when running the command.
    
  • Cast::log msg, source = 'cast', stream = $stdout

    Log a message through the Cast mutex using the given prefix and stream. Output will look like "[prefix] msg". The prefix box will be left out if the argument is nil.

  • Cast::load_groups file -> Hash

    Load Cast groups from the given file, returning them as a hash.

  • Cast::expand_groups cmdgroups, groups = @@groups -> Array

    Takes an array of groups and hosts, and expands the groups into their constituents given the input group hash. If no hash is given, use the value loaded most recently in load_groups. Returns an array of hostnames.

TODO

  • Accept env vars for local and remote commands.
  • Check for duplicate groups in groupfile.
  • Propogate local signals to remote commands.

cast's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.