Parameterize a chef recipe

I have a recipe in the chef that I want to use several times (in several roles), with only a few parameters. I want to be able to use several such roles on the same node.

How can I parameterize a recipe? I cannot use attributes because they are on node, so one role will override the other attributes.

+4
source share
2 answers

The recommended approach in this case is to use a lightweight resource provider or the like.

, runlist , , , 6 , , , .

, -

LWRP , , .

, LWRP, , .

node - , , , .

+3

, . , PatrickWalker ( "... - , .. loop..." ). , -.

  • , JSON, , , .

  • , JSON ( LWRP).

, JSON:

default['config'] = '{"files":[{"name":"/tmp/file_1","content":"file contents 1"},{"name":"/tmp/file_2","content":"file contents 2"}]}'

:

config = JSON.parse("#{node['config']}")
files = config['files']

files.each do |file|
  file "#{file['name']}" do
    content "#{file['content']}"
  end
end

.

0

Source: https://habr.com/ru/post/1527913/


All Articles