Banno/knife-whisk

语言: Ruby

git: https://github.com/Banno/knife-whisk

刀插件生成刀服务器创建命令
Knife plugin to generate knife server create commands
README.md (中文)

刀打蛋器

用于在团队环境中快速启动新服务器的实用程序

whisk

概观

Chef是一个很好的工具,用于配置服务器一旦启动,但它不会解决初始化云服务器的配置管理问题。该工具允许您的团队定义命名服务器和配置混合,以帮助您的团队始终统一创建新服务器。目前,它将根据whisk.yml文件中定义的配置生成刀ec2服务器创建命令。在生成新命令以吐出现有服务器配置的轻微更改时,您可以自由地提供覆盖和其他标志。

总之,这个工具为我们提供了一种“无摩擦”的体验,用于了解如何在我们的组织中创建服务器,以及快速访问以在危机期间正确地重新创建服务器。

用法

假设你已经安装了正确的刀具并且它指向了一个看起来像这样的whisk.yml:

mixins:
  defaults:
    provider: aws
    image: ami-950680fc      # ubuntu instance store
    subnet: subnet-12345678  # private subnet
    region: us-east-1
    user-data: user_data/before_bootstrap.sh
    flavor: m1.small
    ssh-user: ubuntu
    template: chef_full
    security-groups: default
  ebs_instance:
    image: ami-e50e888c
  public_subnet:
    subnet: subnet-87654321

provider_config:
  aws:
    cli_command: "ec2 server create"
    security-groups:
      default: sg-12345678
      java_app_server: sg-34567890
  kvm:
    cli_command: "vm create"

servers:
  app_server:
    mixins:
    - defaults
    config:
      provider: aws
      run-list:
      - "recipe[application-wrapper]"
      security-groups:
      - default
      - java_app_server
      environment: prod

刀拂生成会像这样工作:

$ knife whisk generate app_server
knife ec2 server create --image ami-950680fc --subnet subnet-12345678 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m1.small --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment prod --security-groups-ids sg-12345678,sg-3456789

让我们混合使用public_subnet mixin:

$ knife whisk generate app_server --mixins public_subnet

knife ec2 server create --image ami-950680fc --subnet subnet-87654321 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m1.small --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment prod --security-groups-ids sg-12345678,sg-34567890

看看子网标志是如何更新的?现在让我们试试覆盖。

 $ knife whisk generate app_server --mixins public_subnet --overrides "--environment dev --flavor m2.4xlarge"

knife ec2 server create --image ami-950680fc --subnet subnet-87654321 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m2.4xlarge --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment dev --security-groups-ids sg-12345678,sg-34567890

这是刀拂发光的地方。您无需了解AWS或您使用的任何云提供商的所有细节,只需要在您要启动的服务器上询问默认值或其他任何混音。

最重要的是,作为一个团队,您可以在whisk.yml文件中定义生产服务器的外观,并且您永远不会启动缺少安全组的新节点,因为您忘记了某个辅助服务在需要它的节点上。

使用VPC的安全组很痛苦,所以我们在whisk.yml中添加了一种通过名称调用它们的方法。 knife-whisk会根据“安全组”查找部分中的内容将--security-groups name1,name2转换为--security-groups-id id1,id2。

安装

将此行添加到应用程序的Gemfile:

gem 'knife-whisk'

然后执行:

$ bundle install

或者自己安装:

$ gem install knife-whisk

组态

必须存在whisk.yml文件才能使用刀具。示例目录中有一个示例。可以通过--whisk-config或-C标志在刀具配置中设置文件的路径,或者在.chef目录中默认查找该文件的路径。

最好的方法是将你的whisk.yml放在config /下的chef目录下,然后在你的knife.rb中输入这样的东西。

knife[:whisk_config_file] = "#{ENV['CHEF_REPO_DIR']}/config/whisk.yml"

子命令

此插件提供以下Knife子命令。通过使用--help标志调用子命令可以找到特定的命令选项。

刀拂mixin list

列出可用的mixins

刀拂mixin show

显示mixin详细信息的yaml输出

刀拂服务器列表

列出可用的服务器模板

刀拂过服务器秀

显示服务器详细信息的yaml输出

刀拂尘产生

使用提供的服务器模板,mixins或覆盖输出knife命令。使用--overrides标志时,必须提供长格式标志名称,I.E - 节点名称不是-N。

例子:

knife whisk generate --mixins defaults,public_subnet --overrides "--node-name server1 --image ami-123456"
knife whisk generate application_server
knife whisk generate application_server --mixins public_subnet
knife whisk generate application_server --overrides "--environment dev --node-name dev-application-server"

标签完成

ZSH

此存储库还包含一个zsh文件夹,可替换oh-my-zsh的刀插件。将其复制到〜/ .oh-my-zsh / plugins / knife文件夹,并通过将“knife”添加到.zshrc中的plugins =()来启用插件。您可能需要重新加载shell。

所有

  • 支持--json-attributes刀标志
  • 搅拌加入mixin
  • 拂尘添加服务器
  • 扫描提供商名单
  • bash选项卡完成

作者

  • Nic Grayson(nic.grayson@banno.com)
  • Kevin Nuckolls(kevin.nuckolls@banno.com)
  • Danny Lockard(danny.lockard@banno.com)

如果你想贡献,谢谢!请参阅贡献指南。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

knife-whisk

A utility for quickly whipping up new servers in a team environment

whisk

Overview

Chef is a great tool for configuring servers once they're up, but it doesn't address configuration management for initializing cloud servers in the first place. This tool lets your team define named servers and configuration mixins to help your team always create new servers uniformly. Currently, it will generate knife ec2 server create commands based upon the configuration defined in your whisk.yml file. You're free to provide overrides and additional flags when generating a new command to spit out a slight alteration of an existing server's config.

All together, this tool provides us with a "frictionless" experience for understanding how servers are created in our organization and quick access to recreate them correctly during a crisis.

Usage

Assume you've got knife-whisk installed and configured correctly and it's pointing to a whisk.yml that looks like this:

mixins:
  defaults:
    provider: aws
    image: ami-950680fc      # ubuntu instance store
    subnet: subnet-12345678  # private subnet
    region: us-east-1
    user-data: user_data/before_bootstrap.sh
    flavor: m1.small
    ssh-user: ubuntu
    template: chef_full
    security-groups: default
  ebs_instance:
    image: ami-e50e888c
  public_subnet:
    subnet: subnet-87654321

provider_config:
  aws:
    cli_command: "ec2 server create"
    security-groups:
      default: sg-12345678
      java_app_server: sg-34567890
  kvm:
    cli_command: "vm create"

servers:
  app_server:
    mixins:
    - defaults
    config:
      provider: aws
      run-list:
      - "recipe[application-wrapper]"
      security-groups:
      - default
      - java_app_server
      environment: prod

knife whisk generate will work like this:

$ knife whisk generate app_server
knife ec2 server create --image ami-950680fc --subnet subnet-12345678 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m1.small --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment prod --security-groups-ids sg-12345678,sg-3456789

Let's mix in the public_subnet mixin:

$ knife whisk generate app_server --mixins public_subnet

knife ec2 server create --image ami-950680fc --subnet subnet-87654321 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m1.small --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment prod --security-groups-ids sg-12345678,sg-34567890

See how the subnet flag was updated? Now let's try something with overrides.

 $ knife whisk generate app_server --mixins public_subnet --overrides "--environment dev --flavor m2.4xlarge"

knife ec2 server create --image ami-950680fc --subnet subnet-87654321 --region us-east-1 --user-data user_data/before_bootstrap.sh --flavor m2.4xlarge --ssh-user ubuntu --template chef_full --run-list recipe[application-wrapper] --environment dev --security-groups-ids sg-12345678,sg-34567890

This is where knife-whisk shines. You don't have to be aware of all the ins and outs of AWS or whatever cloud provider you use, you just ask for the defaults or whatever other mixins you need on the server you want to fire up.

Most importantly, as a team you define what your production servers look like in your whisk.yml file and you'll never bring up a new node with a missing security group because you forgot some ancillary service was on the node that needed it.

Security groups with VPC are a pain so we added a way to call them by name in your whisk.yml. knife-whisk will translate the --security-groups name1,name2 to --security-groups-ids id1,id2 according to what is in your "security-groups" lookup section.

Installation

Add this line to your application's Gemfile:

gem 'knife-whisk'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install knife-whisk

Configuration

A whisk.yml file must exist for knife-whisk to work. There is an example in the example directory. The path to the file can be set in your knife config, via the --whisk-config or -C flag, or will look for it by default in your .chef directory.

Best way to do it is to just put your whisk.yml in your chef directory under config/ and put something like this in your knife.rb.

knife[:whisk_config_file] = "#{ENV['CHEF_REPO_DIR']}/config/whisk.yml"

Subcommands

This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a --help flag.

knife whisk mixin list

Lists the available mixins

knife whisk mixin show

Shows the yaml output of the details of the mixin

knife whisk server list

Lists the available servers templates

knife whisk server show

Shows the yaml output of the details of the server

knife whisk generate

Outputs a knife command with the provided server template, mixins, or overrides. When using the --overrides flag you must provide long form flag names, I.E --node-name not -N.

Examples:

knife whisk generate --mixins defaults,public_subnet --overrides "--node-name server1 --image ami-123456"
knife whisk generate application_server
knife whisk generate application_server --mixins public_subnet
knife whisk generate application_server --overrides "--environment dev --node-name dev-application-server"

Tab Completion

ZSH

This repository also includes a zsh folder, with a replacement for oh-my-zsh's knife plugin. Copy that to your ~/.oh-my-zsh/plugins/knife folder, and enabled the plugin by adding "knife" to your plugins=() in your .zshrc. You will likely need to reload your shell.

Todo

  • supprot for --json-attributes knife flag
  • whisk add mixin
  • whisk add server
  • whisk provider list
  • bash tab completion

Authors

If you want to contribute, thanks! Please see contribution guidelines.