如何在命令行中捕获值并将其添加到配方? [英] How I can capture values in command line and add to recipe?

查看:68
本文介绍了如何在命令行中捕获值并将其添加到配方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Chef和Ruby的新手

I am new to Chef and Ruby

我需要在命令行上将两个变量传递给Chef,并在配方中提供这些变量。

I need to pass two variables to Chef on the command line and have those variables available in a recipe.

如何捕获这些值并在Chef中获取它们?

How I can capture these values and get them in Chef?

我需要这样的东西:

before_deploy command 
  execute param1 param2
deploy{ param1/param2}

其中 param1 param2 的值

推荐答案

通过运行来配置计算机时

When you provision the machine by running

chef-solo

chef-client

您不能为这些命令提供任何配方可见的参数。厨师食谱仅适用于属性。好东西(或不太好)是可以在许多不同的地方设置属性:角色,节点,环境和json文件。

you cannot provide any arguments to these commands that can be visible to recipes. Chef recipes work only with attributes. Good thing (or not so good) is that attributes can be set from many different places: roles, nodes, environments and json file.

最接近您的解决方法请求是

The workaround that is nearest to your request is


  • 在计算机上创建一个json文件

  • 在运行<$ c时将其传递$ c> chef-client 或 chef-solo

  • 在食谱中使用属性

  • Create a json-file on the machine
  • Pass it when running chef-client or chef-solo
  • Use attributes in the recipe

例如:apache配置。

For example: apache config.

创建json文件:my_attrs.json

create json file: my_attrs.json

{ 
  "apache": {
    "listen_port": "81",
    "listen_path": "/myapp"
  }
}

,然后在您的食谱:

node[:apache][:listen_port]
node[:apache][:listen_path]

运行首席客户端 chef-solo 带有 -j 标志。

chef-solo -j my_attrs.json

如果my_attrs.json

If my_attrs.json is on some remote server, then you can provide a url.

chef-solo -j http://remote.host/path/my_attrs.json

这篇关于如何在命令行中捕获值并将其添加到配方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆