如何为 nginx 食谱定义自定义属性?

How to define custom attributes for nginx cookbook?

对于我当前的问题,我正在使用 nginx 食谱。我想要做的是从源代码安装它(使用 nginx::source 没问题)并将它作为前缀 /opt/nginx/<version>/,但它总是(默认情况下)作为前缀 /opt/nginx-<version>/ .

这是我的 ./attributes/default.rb:

node.override['nginx']['source']['prefix'] = "/opt/nginx/#{node['nginx']['source']['version']}"
#also tested
override['nginx']['source']['prefix'] = "/opt/nginx/#{node['nginx']['source']['version']}"
#and also
default['nginx']['source']['prefix'] = "/opt/nginx/#{node['nginx']['source']['version']}"

我哪里不明白?

谢谢


另一件事是: - 我如何像上面那样为它添加前缀并创建一个 sym-link 到 /opt/nginx/current(甚至在更新后也这样做)?

所以,这是食谱中的一个缺点。许多变量都是基于那个属性的值构建的,如果您没有首先设置覆盖值,那么食谱中的值仍然会为派生属性取胜。

如果您在 nginx['source']['prefix'] 的节点或环境上设置覆盖应该可行,但它并不理想。或者,也覆盖派生值。

https://github.com/miketheman/nginx/blob/master/attributes/source.rb

default['nginx']['source']['sbin_path'] = "#{node['nginx']['source']['prefix']}/sbin/nginx"
default['nginx']['source']['default_configure_flags'] = %W(
  --prefix=#{node['nginx']['source']['prefix']}  # <= this one needs overridden
  --conf-path=#{node['nginx']['dir']}/nginx.conf
  --sbin-path=#{node['nginx']['source']['sbin_path']}
)

可能还有其他人,但这是我所知道的两个,而且很突出。