shift31 / hostbase-cli
Hostbase CLI
Requires
- illuminate/console: ~4
- kherge/amend: 3.*
- shift31/hostbase-api-client: 0.2.*
- symfony/yaml: 2.6.*
This package is not auto-updated.
Last update: 2020-01-20 03:30:38 UTC
README
Hostbase CLI具有全文搜索功能(使用Elasticsearch/Lucene查询语法)和基本的CRUD操作,接受JSON格式。
安装
-
下载PHAR文件:https://github.com/shift31/hostbase-cli/raw/master/hostbase.phar
-
将其移动到/usr/local/sbin并重命名为'hostbase'
-
使其可执行
chmod +x /usr/local/sbin/hostbase
配置
在/etc或您的家目录中创建hostbase-cli.config.php
<?php return array( 'baseUrl' => 'http://your.hostbase.server' );
针对Hostbase开发服务器的配置
<?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
IP地址
hostbase ips [-j|--json] [-k|--key="..."] [-s|--search] [-l|--limit="..."] [-x|--extendOutput] [-a|--add="..."] [-u|--update="..."] [-d|--delete] ip|query
添加主机
示例:添加具有必填字段'fqdn'和其他(任意)字段的宿主
-
原始JSON字符串
hostbase hosts -a '{"fqdn": "hostname.domain.tld", "fooField": "barValue"}' hostname.domain.tld -
使用Bash子shell的.json文件
host.json
{ "fqdn": "hostname.example.com", "fooField": "barValue" }hostbase hosts -a "$(cat host.json)" hostname.example.com
更新主机
示例:添加字段(键/值对)
-
原始JSON字符串
hostbase hosts -u '{"anotherField": "someValue"}' hostname.domain.tld -
使用Bash子shell的.json文件
host.json
{ "anotherField": "someValue" }hostbase hosts -u "$(cat host.json)" hostname.example.com
通过FQDN查找主机
-
输出Yaml(默认)
hostbase hosts hostname.example.com
-
输出JSON
hostbase hosts -j hostname.example.com
搜索主机
-
示例:'domain'包含'example.com'
hostbase hosts -s 'domain:example.com' -
显示所有主机数据(输出Yaml)
hostbase hosts -sx 'domain:example.com' -
仅返回特定字段/键的值(以'operatingsystem'为例)
当请求单个主机时,这也适用。
hostbase hosts -s 'domain:example.com' -k operatingsystem -
列出所有主机
hostbase hosts -s ""
删除主机
hostbase hosts -d hostname.example.com
其他实体
'subnets'和'ips'命令与'hosts'命令的工作方式相同
Laravel Envoy
使用Laravel Envoy,您可以轻松地在多个服务器上运行任务(串行或并行)。以下是一个示例 Envoy.blade.php,它从 hostbase 的输出中检索主机数组,然后逐个在每台服务器上运行 ls -la
<?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