Chef-Solo包装器
项目描述
chef-solo-cup
Chef Solo Cup是一个围绕chef-solo的包装器,用于启动/更新AWS实例
安装
使用PIP
从GitHub
pip install git+git://github.com/josegonzalez/chef-solo-cup.git#egg=beaver
从PyPI
pip install chef-solo-cup
用法
CLI用法如下
usage: chef-solo-cup [-h] [-a ASG_DNA_PATH] [-b BLACKLIST_RULE] [-c CMD]
[-C CONFIG_PATH] [-d DNA_PATTERNS [DNA_PATTERNS ...]]
[-D] [-e EXCLUDE [EXCLUDE ...]]
[-E RSYNC_EXCLUSIONS [RSYNC_EXCLUSIONS ...]]
[-i IP_ADDRESS] [-k KEY_FILENAME]
[-l {debug,info,warn,error,fatal}] [-L LOG_PATH]
[-o OUTPUT] [-P] [-p [PROVIDERS [PROVIDERS ...]]]
[-q QUANTITY] [-r [REGIONS [REGIONS ...]]]
[-R REPOSITORY] [-s [SERVICES [SERVICES ...]]]
[-S {git,rsync}] [-t TAGS [TAGS ...]] [-u USER] [-v]
[--api-password API_PASSWORD] [--api-url API_URL]
[--api-username API_USERNAME] [--dry-run]
[--chef-version CHEF_VERSION]
[--ohai-version OHAI_VERSION]
[--chef-file-dest CHEF_FILE_DEST]
[--aws-access-key-id AWS_ACCESS_KEY_ID]
[--aws-secret-access-key AWS_SECRET_ACCESS_KEY]
[--use-private-ips]
[--use-alternate-databag USE_ALTERNATE_DATABAG]
[{bootstrap,chef,clean,default,gem,inspect,ruby,run,sync,sudo,test,update}]
Chef-solo-cup, a chef-solo wrapper
positional arguments:
{bootstrap,chef,clean,default,gem,inspect,ruby,run,sync,sudo,test,update}
command to run
optional arguments:
-h, --help show this help message and exit
-a ASG_DNA_PATH, --asg-dna-path ASG_DNA_PATH
Path to asg dna files (relative to repo base)
-b BLACKLIST_RULE, --blacklist-rule BLACKLIST_RULE
pattern to use to blacklist hosts
-c CMD, --command CMD
command to run
-C CONFIG_PATH, --config-path CONFIG_PATH
relative path from chef file destination to solo
config file
-d DNA_PATTERNS [DNA_PATTERNS ...], --dna-patterns DNA_PATTERNS [DNA_PATTERNS ...]
space-separated list of patterns to match against dna
filenames
-D, --debug enable debug mode
-e EXCLUDE [EXCLUDE ...], --exclude EXCLUDE [EXCLUDE ...]
A regex to exclude hosts by
-E RSYNC_EXCLUSIONS [RSYNC_EXCLUSIONS ...], --rsync-exclusions RSYNC_EXCLUSIONS [RSYNC_EXCLUSIONS ...]
space-separated list of files to exclude in rsync
-i IP_ADDRESS, --ip-address IP_ADDRESS
The ip address to connect to
-k KEY_FILENAME, --key-filename KEY_FILENAME
full path to key filename (pem key)
-l {debug,info,warn,error,fatal}, --loglevel {debug,info,warn,error,fatal}
The chef log level to use
-L LOG_PATH, --log-path LOG_PATH
The path to write logs to
-o OUTPUT, --output OUTPUT
file to pipe output to (in addition to stdout)
-P, --parallel whether to run commands in parallel
-p [PROVIDERS [PROVIDERS ...]], --providers [PROVIDERS [PROVIDERS ...]]
space-separated list of providers
-q QUANTITY, --quantity QUANTITY
The number of nodes to provision
-r [REGIONS [REGIONS ...]], --regions [REGIONS [REGIONS ...]]
space-separated list of regions
-R REPOSITORY, --repository REPOSITORY
repository to use when cloning instead of using rsync
-s [SERVICES [SERVICES ...]], --services [SERVICES [SERVICES ...]]
space-separated list of services
-S {git,rsync}, --sync {git,rsync}
method to sync chef with
-t TAGS [TAGS ...], --tags TAGS [TAGS ...]
tags to filter instances by
-u USER, --user USER user to run commands as
-v, --version Print version and exit
--api-password API_PASSWORD
basic auth password for api
--api-url API_URL backing url for api
--api-username API_USERNAME
basic auth username for api
--dry-run perform a dry run of all commands
--chef-version CHEF_VERSION
chef version to install
--ohai-version OHAI_VERSION
ohai version to install
--chef-file-dest CHEF_FILE_DEST
chef file destination on disk
--aws-access-key-id AWS_ACCESS_KEY_ID
AWS Access Key
--aws-secret-access-key AWS_SECRET_ACCESS_KEY
AWS Secret Key
--use-private-ips Connect to the instances via the private ip address
instead of the public
--use-alternate-databag USE_ALTERNATE_DATABAG
Use alternate databag instead of one defined by ASG
name
Chef Solo Cup is pwnage
即将推出
技术描述
命令
# the binary
chef-solo-cup
# running commands
chef-solo-cup [command] <required argument> (optional argument) -f {optional flag}
# run help
chef-solo-cup help
# get a summary of running instances with regions
chef-solo-cup status (group)
# start|stop|terminate a set of instances
chef-solo-cup start|stop|terminate
<group>
--number {number}
--region {region}
--size {size}
--before {run this before}
--after {run this after}
--parallel
# update a set of instances
# will not update instances by default, must specify a group or the flag
chef-solo-cup update (group)
--all
--parallel
参数和标志的解释
group: 要使用的盒子组名称;下面将详细解释盒子组。也支持正则表达式用于盒子组。
number: 受影响的实例数量。对于关闭实例,将影响最后n个实例
region: 此命令将运行的亚马逊区域。将尝试在区域之间平衡负载
size: 启动的盒子大小,如c1.medium或m1.large
before: 在运行chef-solo-flight之前运行此命令。将访问chef-solo-flight参数
after: 在运行chef-solo-flight之后运行此命令。将访问chef-solo-flight参数
parallel: 并行针对所有这些实例运行chef-solo-flight。可能有些奇怪。
all: 针对所有可用实例运行
盒子组
盒子组是一组服务器的定义。在典型的面向服务器的架构中,您将拥有几个具有相同目的的服务器。例如,可能需要10个具有特定存储卷的后台工作者。这些最有可能使用相同的chef设置,而不是在多个JSON文件中重复此信息,我们将创建一个包含此信息的单个JSON“模板”。
以下是假设的boxes/bee.json内容
{
"_box": {
"service": "sg",
"storage": [
{
"size": "50",
"mount": "/dev/sdf",
"snapshot": "343qu4rhiqhe"
}
],
"region": "us-east-1a",
"size": "c1.medium",
"provider": "ec2",
"ami": "ami-6fa27506",
"security_groups": [ "sg-123456", "sg-789012" ]
},
"run_list": [
"role[bee]"
]
}
在我们的案例中,您会注意到我们可以指定要附加到实例的存储单元、分配实例的区域以及实例大小。这些内容位于 _box 最高级键下,而 box.json 文件中的所有其他键/值都将复制到特定实例的 dna.json 中。
_box 是一个魔术键。请勿将其用于您的个人用途。它仅应用于定义箱组。
还有一个特殊的 service 键,用于创建实例 DNA,如下所示
``:service-:box_group-:provider-:region_shorthand-:number.json``
箱子的名称将与文件名相同,但不包括 json 扩展名。
这些键定义如下
service: 这个服务是什么名称?当管理大多独立的基础设施时很有用,例如单个组织下的不同网站
box_group: 从您的箱组 json 文件中猜测的名称。在上面的 json 中,这将是一个 bee
provider: 云提供商的名称。目前,默认为 ec2。目前不支持其他选项
region_shorthand: 所有 AWS 区域都有一个缩写,例如 use1a 代表 us-east-1a。这些很容易猜测,并且会自动从您的箱组或作为 chef-solo-cup 命令的标志中猜测。
number: 实例编号。这基于当前已部署的实例数量以及正在部署的实例数量。将是一个零填充的 5 位数字。
如果您认为您将只使用单个区域,或者将拥有多个 chef-solo-cup 安装,则可以覆盖命名模式。这可以在您的 solo-cup-config.rb 文件中覆盖。
配置管理
每个 chef-solo-cup 安装都可以访问一个 solo-cup-config.rb 配置文件。除了存储之外,默认的箱配置可以在此指定。特定箱组的 _box 配置将与 solo-cup-config.rb 中的配置合并。这些可以在 chef-solo-cup 命令上使用参数在运行时覆盖。
# A sample solo-cup-config.rb # some good defaults service "sg" region "us-east-1a" size "c1.medium" ami "ami-6fa27506" # These are defaults, and other groups are merged ONTO these # default is the "default" security group security_groups [ "sg-123456", "sg-789012" ] # Limit overrides to the following keys allow_override [ :ami, :size ] # Turn on parallel deploys, it's off by default parallel true # Path to generated dna files dna_path "./recipes/dna" dna_name_template ":service-:box_group-:provider-:region_shorthand-:number" # aws auth info aws_access_key_id: AAAAAAAAAAAAAAAAAAAA aws_secret_access_key: iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii # stuff for chef/ruby chef_version 0.10.10 ohai_version 6.14.0 chef_version 10.12.0
DNA 生成
生成的 DNA 将遵循您指定的任何箱组,以及 _box 中可用的自定义配置。如果您想使用我们上面的箱组再启动 1 个 bee 实例,而我们已经有 4 个 bee 实例,那么生成的 dna.json 将如下所示
{
"_box": {
"service": "sg",
"storage": [
{
"size": "50",
"mount": "/dev/sdf",
"snapshot": "343qu4rhiqhe"
}
],
"region": "us-east-1a",
"size": "c1.medium",
"provider": "ec2",
"ami": "ami-6fa27506",
"security_groups": [ "sg-123456", "sg-789012" ]
},
"box_name": "sg-bee-ec2-use1a-05",
"run_list": [
"role[bee]"
]
}
默认情况下,DNA 文件将放置在 ./recipes/dna,并从该路径部署。这样,您可以将 DNA 文件作为您的 chef cookbooks 的一部分或其子模块。
DNA 文件将生成到以下路径
:dna_path/:provider/:region/:dna_name_template.json
此 DNA 路径用于允许 chef-solo-cup 进行更快的过滤。
DNS 集成
请在配方中处理此问题。仅工具可能会出错。您可以使用 node[:box_name] 来确定实例的别名。
AWS 集成
如果您指定了 AWS 凭据(希望是在文件中而不是在 CLI 中)和区域,chef-solo-cup 可以查询自动扩展组来引入更多节点。这些目前正在 dna/asg 中查找 DNA 文件。
引用其他节点
我们如何模拟 chef-server?您想要了解不同节点的主要原因是为了能够根据其他节点编写配置文件到服务、数据存储等。
因为我们知道其他节点的角色,所以我们可能可以在 dna.json 中的 nodes 属性内加载每个节点的 json。这可以动态编译,并在运行时合并。
潜在问题
因为您一直在配置新服务器,如何通知旧服务器新服务器已上线?* 可以在命令后添加注释以检测配置的变化 - up 和 down 默认更改内容,update 可以通过将现有 json 与服务器 json 进行哈希比较来检测变化,并给用户提供适当的更新所有实例的注释
新实例的 DNS 很好地包含在其他实例的 /etc/hosts 文件中 * chef-solo-cup bulk 可能能够将单个 dna.json 投放到所有实例 - 通过标志进行过滤 - 这样我们可以快速运行一些菜谱来更新关键基础设施
没有搜索功能,不知道内联安装了哪些库或软件包等。* 您的菜谱应该明确说明在哪个节点上安装了哪个库,然后您可以根据盒子组推断出这一点。
项目详情
chef-solo-cup-0.3.1.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | bd38e99b04cef3844356f966f32280d1cb260c3d3df405e536a9208f27390bac |
|
| MD5 | 523a575dc4d9f4b50bdf8df1047801af |
|
| BLAKE2b-256 | ba7b2b77a601a8be9ccd9cf3cb9c5e664296099de55b9612b94780eb49f6546d |