小编Rav*_*mar的帖子

访问食谱中的厨师数据包

我创建了以下数据包项目:

{
  "name": "data_bag_item_nameservers_servers",
  "json_class": "Chef::DataBagItem",
  "chef_type": "data_bag_item",
  "data_bag": "nameservers",
  "raw_data": {
    "id": "servers",
    "serverslist": [
      "xxx.xxx.xxx.xxx",
      "xxx.xxx.xxx.xxx"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

在模板erb中我添加了以下调用,

<% @serverslist.each_with_index do |nmserver| %>
nameserver <%= nmserver %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

但它不适合我,并给出错误,因为,

在资源'template [/etc/resolve.conf]上执行操作创建时出错

厨师::密新::模板:: TemplateError

undefined方法each_with_index'为nil:NilClass

有人可以帮助我如何在食谱食谱中调用这些数据包项值?

提前致谢!

ruby-on-rails cookbook chef-infra

4
推荐指数
1
解决办法
5177
查看次数

与 echo 同等地缩进行

我正在努力抓取一个文件,同时将其与一些文字一起打印。

例如:

/root/文件包含:

line1
line2
line3
Run Code Online (Sandbox Code Playgroud)

脚本:

#!/bin/bash
echo -en "Printing Line of the file: `cat /root/file`\n"
Run Code Online (Sandbox Code Playgroud)

结果:

Printing Line of the file: line1
 line2
 line3
Run Code Online (Sandbox Code Playgroud)

预期结果:

Printing Line of the file:  line1
                            line2
                            line3
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到我想要的输出?

bash shell

3
推荐指数
1
解决办法
7255
查看次数

如何在双引号内将perl变量传递给反引号

我正在编写一个perl脚本,我需要将perl变量传递给反引号,并且该变量应该在双引号内声明为反引号.例如:我的$ variable =`df -Ph | grep -i"$ var1"`

perl

0
推荐指数
1
解决办法
1917
查看次数

标签 统计

bash ×1

chef-infra ×1

cookbook ×1

perl ×1

ruby-on-rails ×1

shell ×1