The Hostbase CLI features full-text search (using Elasticsearch/Lucene query syntax) and basic CRUD operations, which accept JSON.
-
Download the PHAR: https://github.com/shift31/hostbase-cli/raw/master/hostbase.phar
-
Move it to /usr/local/sbin and rename it to 'hostbase'
-
Make it executable:
chmod +x /usr/local/sbin/hostbase
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:
[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
hostbase hosts [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] fqdn|query
hostbase subnets [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] subnet|query
hostbase ips [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] ip|query
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
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
-
Output Yaml (default):
hostbase hosts hostname.example.com
-
Output JSON:
hostbase hosts -j hostname.example.com
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 ""
hostbase hosts -d hostname.example.com
The 'subnets' and 'ips' commands work the same way as 'hosts'
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