问题描述
在建立自己的食谱时,我发现自己在这个周期内不断:
- 在本地计算机上更改食谱
- 将修改后的食谱上传到厨师服务器
- 在远程计算机上运行厨师客户端
- 重复
由于我是厨师新手,所以我会经常极端重复该循环,但是我发现从厨师服务器上来如此频繁的上载和下载非常麻烦。
经验丰富的厨师用户如何缓解这一周期?我通过免费的托管解决方案学习了Chef,但是我不确定是否应该只使用Chef-solo更好,并且一旦我拥有很多服务器并且对Chef有了更多的经验,以后再回到托管版本。
也许有一个工作流程,可以在使用托管Chef时而不在上载的情况下直接在远程计算机上直接尝试对食谱进行更改?
我使用在笔记本电脑上本地完成所有开发工作。准备好菜谱后,它会被推送到新的Git存储库主页,并集成到我的生产厨师服务器基础结构中。
以下示例在virtualbox映像上运行nginx。 / p>
示例
安装无业游民的插件(只需执行一次):
vagrant插件安装vagrant-omnibus
vagrant插件安装vagrant-berkshelf
vagrant插件安装vagrant-chef-zero
使用来生成一个新的。
$ berks食谱演示
创建演示/文件/默认
创建演示/模板/默认
创建演示/属性
创建演示/定义
创建演示/库
创建演示/提供者
创建演示/配方
创建演示/资源
创建演示/食谱/default.rb
创建演示/metadata.rb
创建演示/许可
创建演示/README.md
创建演示/ Berksfile
创建演示/ Thorfile
创建演示/ chefignore
创建演示/.gitignore
从 ./demo运行git init
创建demo / Gemfile
创建demo / Vagrantfile
编辑以下文件(以下详细信息):
- Vagrantfile<-控制流浪者的操作
- metadata.rb<-列出社区食谱依赖项
- 食谱/default.rb<-调用社区食谱和LWRP
正在运行的vagrant将启动使用Chef-client设置的虚拟机。 插件将运行chef-server的本地嵌入式实例。 berkself插件用于自动加载菜谱依赖项。
无所事事
以下命令将重新运行Chef-client(以下编辑):
<$最后,使用本地虚拟化进行开发的真正最大优势是:
您可以拆除所有内容并从头开始构建它:
vavrant destroy -f&流浪汉
Vagrantfile
控制流浪者的操作。在这种情况下,我只启动使用Chef-client进行配置的单个VM:
Vagrant.require_plugin vagrant-omnibus
Vagrant.require_plugin vagrant-berkshelf
Vagrant.require_plugin vagrant-chef-zero
VAGRANTFILE_API_VERSION = 2
Vagrant.configure (VAGRANTFILE_API_VERSION)做| config |
#框配置
config.vm.box = saucy64
config.vm.box_url = http://cloud-images.ubuntu.com/vagrant/saucy /current/saucy-server-cloudimg-amd64-vagrant-disk1.box
#Virtualbox config
config.vm.provider:virtualbox do | vb |
vb.customize [ modifyvm,:id, --memory,1024]
结尾
#网络配置
config.vm.network private_network ,ip: 10.0.0.10
#插件配置
config.omnibus.chef_version =:latest
config.chef_zero.enabled = true
config.berkshelf .enabled = true
#Chef config
config.vm.provision:chef_client do | chef |
Chef.add_recipe演示
结束
结束
omnibus插件负责安装所需版本的Chef。 Berkshelf插件将下载食谱依赖项,并与Chef-zero结合使用时,将在每次配置运行期间上载食谱。
metadata.rb
将nginx添加为菜谱依赖项:
name'demo'
维护者'YOUR_NAME'
maintenanceer_email'YOUR_EMAIL'
许可证'保留所有权利'
描述'安装/配置演示'
long_description IO.read(File.join(File.dirname(__ FILE__),'README。 md'))
版本'0.1.0'
取决于 nginx
Berksfile 已预先配置为从社区食谱库中加载元数据文件中列出的食谱依赖项。
site:opscode
元数据
recipes / default.rb
运行默认的nginx配方
#
#食谱名称::演示
#配方::默认
#
#版权所有(C)2014 YOUR_NAME
#
#保留所有权利-不要重新分发
#
include_recipe nginx
While building my own cookbooks I find myself constantly within this cycle:
- Change cookbook on my local computer
- Upload modified cookbook to chef server
- Run chef-client on remote machine
- Repeat
Since I am new to chef, I repeat that cycle extremely often, but I find rather cumbersome uploading and downloading so frequently from the chef server.
How experienced chef users ease this cycle? I learnt Chef with the free hosted solution, but I am not sure if I should be better off using just Chef-solo and move back later to the hosted version once I have many servers and more experience with chef.
Is there maybe a workflow where I can quickly try changes to my cookbooks directly on my remote machine while using hosted Chef but without uploading them?
I do all my development locally on my laptop, using Vagrant. When the cookbook is ready, it gets pushed to it's new Git repository home and integrated into my production chef server infrastructure.
The following example runs nginx on a virtualbox image.
Example
Install vagrant plugins (only needs to be done once):
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-chef-zero
Use Berkshelf to generate a new application cookbook.
$ berks cookbook demo
create demo/files/default
create demo/templates/default
create demo/attributes
create demo/definitions
create demo/libraries
create demo/providers
create demo/recipes
create demo/resources
create demo/recipes/default.rb
create demo/metadata.rb
create demo/LICENSE
create demo/README.md
create demo/Berksfile
create demo/Thorfile
create demo/chefignore
create demo/.gitignore
run git init from "./demo"
create demo/Gemfile
create demo/Vagrantfile
Edit the following files (Details below):
- Vagrantfile <-- Controls vagrant's operation
- metadata.rb <-- List community cookbook dependencies
- recipes/default.rb <-- Calls to community cookbook recipes and LWRPs
Running vagrant will startup a virtual machine that is provisioned using chef-client. The chef zero plugin will run a local embedded instance of chef-server. The berkself plugin is used to automatically load the cookbook dependencies.
vagrant up
The following command will rerun chef-client (following edits):
vagrant provision
Finally, the really big advantage of doing development, using local virtualization, is that you can tear everything down and build it again from scratch:
vagrant destroy -f && vagrant up
Vagrantfile
Controls vagrant's operation. In this case I'm only starting a single VM, provisioned using chef-client:
Vagrant.require_plugin "vagrant-omnibus"
Vagrant.require_plugin "vagrant-berkshelf"
Vagrant.require_plugin "vagrant-chef-zero"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Box config
config.vm.box = "saucy64"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box"
# Virtualbox config
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 1024]
end
# Networking config
config.vm.network "private_network", ip: "10.0.0.10"
# Plugin config
config.omnibus.chef_version = :latest
config.chef_zero.enabled = true
config.berkshelf.enabled = true
# Chef config
config.vm.provision :chef_client do |chef|
chef.add_recipe "demo"
end
end
The omnibus plugin is responsible for installing the desired version of chef. The Berkshelf plugin will download cookbook dependencies and when combined with chef-zero will upload cookbooks during each provision run.
metadata.rb
Add nginx as a cookbook dependency:
name 'demo'
maintainer 'YOUR_NAME'
maintainer_email 'YOUR_EMAIL'
license 'All rights reserved'
description 'Installs/Configures demo'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
depends "nginx"
The Berksfile is preconfigured to load the cookbook dependencies, listed in the metadata file, from the community cookbook repository.
site :opscode
metadata
recipes/default.rb
Run the default nginx recipe
#
# Cookbook Name:: demo
# Recipe:: default
#
# Copyright (C) 2014 YOUR_NAME
#
# All rights reserved - Do Not Redistribute
#
include_recipe "nginx"
这篇关于新食谱的厨师工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!