shift31/hostbase-cli

This package is abandoned and no longer maintained. No replacement package was suggested.

The Hostbase CLI

0.2.0 2015-02-02 05:11 UTC

This package is not auto-updated.

Last update: 2020-01-20 03:30:38 UTC


README

The Hostbase CLI features full-text search (using Elasticsearch/Lucene query syntax) and basic CRUD operations, which accept JSON.

Installation

  1. Download the PHAR: https://github.com/shift31/hostbase-cli/raw/master/hostbase.phar

  2. Move it to /usr/local/sbin and rename it to 'hostbase'

  3. Make it executable:

    chmod +x /usr/local/sbin/hostbase

Configuration

Create hostbase-cli.config.php in /etc or your home directory:

<?php

 return array(
     'baseUrl' => 'http://your.hostbase.server'
 );

Configuration for Hostbase Development Server:

<?php

 return array(
     'baseUrl' => 'http://hostbase.192.168.33.10.xip.io'
 );

Usage

Help

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --env               The environment the command should run under.

Available commands:
  help          Displays help for a command
  hosts         View and manipulate hosts
  ips           View and manipulate IP addresses
  list          Lists commands
  self-update   Updates the application.
  subnets       View and manipulate subnets

Hosts

hostbase hosts [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] fqdn|query

Subnets

hostbase subnets [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] subnet|query

IP Addresses

hostbase ips [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] ip|query

Add a host

Example adding a host with the mandatory 'fqdn' field and another (arbitrary) field:

  • Raw JSON string:

    hostbase hosts -a '{"fqdn": "hostname.domain.tld", "fooField": "barValue"}' hostname.domain.tld
  • .json file using Bash subshell:

    host.json:

    {
        "fqdn": "hostname.example.com",
        "fooField": "barValue"
    }
    hostbase hosts -a "$(cat host.json)" hostname.example.com

Update a host

Example adding a field (key/value pair):

  • Raw JSON string:

    hostbase hosts -u '{"anotherField": "someValue"}' hostname.domain.tld
  • .json file using Bash subshell:

    host.json:

    {
        "anotherField": "someValue"
    }
    hostbase hosts -u "$(cat host.json)" hostname.example.com

Find a host by FQDN

  • Output Yaml (default):

    hostbase hosts hostname.example.com
  • Output JSON:

    hostbase hosts -j hostname.example.com

Search for a host

Use Elasticsearch/Lucene query syntax

  • Example where 'domain' contains 'example.com'

    hostbase hosts -s 'domain:example.com'
  • Show all host data (output Yaml)

    hostbase hosts -sx 'domain:example.com'
  • Only return values for a specific field/key (using 'operatingsystem' as example)

    This also works when requesting a single host.

    hostbase hosts -s 'domain:example.com' -k operatingsystem
  • List all hosts

    hostbase hosts -s ""

Delete a host

hostbase hosts -d hostname.example.com

Other entities

The 'subnets' and 'ips' commands work the same way as 'hosts'

Laravel Envoy

Using Laravel Envoy, you can easily run tasks on multiple servers (in serial or parallel). Here's an example Envoy.blade.php that retrieves an array of hosts from the output of hostbase and runs ls -la on each server, one at a time:

<?php
$servers = [];
exec('hostbase hosts -s "env:prod AND role:www"', $servers);

$credentials = [];

foreach ($servers as $server) {
  $credentials[$server] = 'root@' . $server;
}
?>

@servers($credentials)

@task('foo', ['on' => $servers])
ls -la
@endtask