Ruby中attributes字符串不匹配的Chef错误如何解决?

2026-04-11 15:221阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计631个文字,预计阅读时间需要3分钟。

Ruby中attributes字符串不匹配的Chef错误如何解决?

我在`attributes/default.rb`文件中处理类属性时遇到了命名错误。我有两个属性:`default['test']['webservice']['https']['keyManagerPwd']='password'` 和 `default['test']['webservice']['https']['key']`。

我似乎无法解决在我的attributes / default.rb文件中处理类似命名属性的厨师错误.

我有2个属性:

Ruby中attributes字符串不匹配的Chef错误如何解决?

default['test']['webservice']['https']['keyManagerPwd'] = 'password' ... ... default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

请注意,直到最后一个括号([‘type’]),名称是相同的.

我在模板和配方中的模板块中引用这些属性.当我去运行它时,我收到此错误:

==================================================[0m I, [2015-01-28T13:36:43.668692 #7920] INFO -- core-14-2-centos-65: [31mRecipe Compile Error in /tmp/kitchen/cache/cookbooks/avx/attributes/default.rb[0m I, [2015-01-28T13:36:43.669192 #7920] INFO -- core-14-2-centos-65: =================================================================[0m I, [2015-01-28T13:36:43.669192 #7920] INFO -- core-14-2-centos-65: I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: [0mIndexError[0m I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: ------- --[0m I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: string not matched[0m I, [2015-01-28T13:36:43.670192 #7920] INFO -- core-14-2-centos-65: I, [2015-01-28T13:36:43.670192 #7920] INFO -- core-14-2-centos-65: [0mCookbook Trace:[0m I, [2015-01-28T13:36:43.670692 #7920] INFO -- core-14-2-centos-65: --------[0m I, [2015-01-28T13:46:05.101875 #8332] INFO -- core-14-2-centos-65: [0m113>> default['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

当唯一的区别是结束时,似乎Chef无法区分2个属性.
如果我通过在名称的前面放置一些独特的文本来修改相同的属性,则根本没有配方问题:

default['test']['1']['webservice']['https']['keyManagerPwd'] = 'password' ... ... default['test']['2']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

通过将[‘1’]和[‘2’]放在那里,它解决了问题.

我对Chef很新,所以我觉得它只是简单的我忽略了.有没有人有任何想法或建议?谢谢.

简单回答:你不能这样做.这不是厨师问题,也不是ruby问题 – 这是大多数编程语言的普遍问题.

让我们使用foo作为变量而不是冗长的默认[‘test’] [‘webservice’] [‘https’] [‘keyManagerPwd’].

你有效地做了什么

1: foo = "password" 2: foo['type'] = "encrypted"

在第1行中,foo是一个字符串.在第2行中,它被视为散列(在其他一些语言中称为数组).第二行自动覆盖你的foo =“密码”赋值.它实际上是一样的

1: foo = "password" 2: foo = {} 3: foo['type'] = "encrypted"

替代方案是使用

foo['something'] = "password" foo['type'] = "encrypted"

或者翻译成你的代码:

default['test']['webservice']['https']['keyManagerPwd']['something'] = 'password' default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

这应该工作.

本文共计631个文字,预计阅读时间需要3分钟。

Ruby中attributes字符串不匹配的Chef错误如何解决?

我在`attributes/default.rb`文件中处理类属性时遇到了命名错误。我有两个属性:`default['test']['webservice']['https']['keyManagerPwd']='password'` 和 `default['test']['webservice']['https']['key']`。

我似乎无法解决在我的attributes / default.rb文件中处理类似命名属性的厨师错误.

我有2个属性:

Ruby中attributes字符串不匹配的Chef错误如何解决?

default['test']['webservice']['https']['keyManagerPwd'] = 'password' ... ... default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

请注意,直到最后一个括号([‘type’]),名称是相同的.

我在模板和配方中的模板块中引用这些属性.当我去运行它时,我收到此错误:

==================================================[0m I, [2015-01-28T13:36:43.668692 #7920] INFO -- core-14-2-centos-65: [31mRecipe Compile Error in /tmp/kitchen/cache/cookbooks/avx/attributes/default.rb[0m I, [2015-01-28T13:36:43.669192 #7920] INFO -- core-14-2-centos-65: =================================================================[0m I, [2015-01-28T13:36:43.669192 #7920] INFO -- core-14-2-centos-65: I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: [0mIndexError[0m I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: ------- --[0m I, [2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: string not matched[0m I, [2015-01-28T13:36:43.670192 #7920] INFO -- core-14-2-centos-65: I, [2015-01-28T13:36:43.670192 #7920] INFO -- core-14-2-centos-65: [0mCookbook Trace:[0m I, [2015-01-28T13:36:43.670692 #7920] INFO -- core-14-2-centos-65: --------[0m I, [2015-01-28T13:46:05.101875 #8332] INFO -- core-14-2-centos-65: [0m113>> default['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

当唯一的区别是结束时,似乎Chef无法区分2个属性.
如果我通过在名称的前面放置一些独特的文本来修改相同的属性,则根本没有配方问题:

default['test']['1']['webservice']['https']['keyManagerPwd'] = 'password' ... ... default['test']['2']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

通过将[‘1’]和[‘2’]放在那里,它解决了问题.

我对Chef很新,所以我觉得它只是简单的我忽略了.有没有人有任何想法或建议?谢谢.

简单回答:你不能这样做.这不是厨师问题,也不是ruby问题 – 这是大多数编程语言的普遍问题.

让我们使用foo作为变量而不是冗长的默认[‘test’] [‘webservice’] [‘https’] [‘keyManagerPwd’].

你有效地做了什么

1: foo = "password" 2: foo['type'] = "encrypted"

在第1行中,foo是一个字符串.在第2行中,它被视为散列(在其他一些语言中称为数组).第二行自动覆盖你的foo =“密码”赋值.它实际上是一样的

1: foo = "password" 2: foo = {} 3: foo['type'] = "encrypted"

替代方案是使用

foo['something'] = "password" foo['type'] = "encrypted"

或者翻译成你的代码:

default['test']['webservice']['https']['keyManagerPwd']['something'] = 'password' default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

这应该工作.