chef-recipe

How to lazily evaluate an arbitrary variable with Chef

混江龙づ霸主 提交于 2019-11-30 08:47:00
I'm writing a Chef recipe to install our application code and execute it. The recipe needs to be particular about the directory this code ends up in (for running templates, setting log forwarding etc.). Thus the directory itself pops up in a lot of places in different recipes. I am trying to fetch/define a variable so I can re-use it in my resource block with string interpolation. This is pretty straightforward: home = node['etc']['passwd'][node['nodejs']['user']]['dir'] With an example usage being to run npm install while telling it to plunk the repo downloads in the home directory, like this

Ruby code blocks and Chef

流过昼夜 提交于 2019-11-29 15:53:34
I am an extremely new person to Ruby and Chef. I have been trying to wrap my head around the syntax and do some research, but I am sure as you all know unless one knows the terminology, it is hard to find what you are looking for. I have read up on Ruby code blocks, but the Chef code blocks still confuse me. I see something like this for example: log "a debug string" do level :debug end Which adds "a debug string" to the log. From what I have seen though, it seems to me like it should be represented as: log do |message| #some logic end Chef refers to these as resources. Can someone please help

How to use a Ruby block to assign variables in chef recipe

 ̄綄美尐妖づ 提交于 2019-11-29 08:33:37
I am trying to execute Ruby logic on the fly in a Chef recipe and believe that the best way to achieve this is with a block. I am having difficulty transferring variables assigned inside the block to the main code of the chef recipe. This is what I tried: ruby_block "Create list" do block do to_use ||= [] node['hosts'].each do |host| system( "#{path}/command --all" \ " | awk '{print $2; print $3}'" \ " | grep #{host} > /dev/null" ) unless $? == 0 to_use << host end end node['hosts'] = to_use.join(',') end action :create end execute "Enable on hosts" do command "#{path}/command --enable -N #

Copy file from chef client node to workstation

◇◆丶佛笑我妖孽 提交于 2019-11-29 08:05:28
I would like to know how to transfer a file from a client node to a remote machine. I have checked whether there any resource available for doing this. The closest thing I found is remote_file , but it is fetching a file from remote location and transfer it to the client node. So I tried another option by writing a bash script which will perform an automated scp. But I cant able to copy the file, but the chef-client was running fine without showing any errors. Here is my script for copying the file: #!/usr/bin/expect -f # connect via scp spawn scp "/tmp/testfile" chef-ws@10.232.110.113:/home

Ruby code blocks and Chef

◇◆丶佛笑我妖孽 提交于 2019-11-28 09:44:35
问题 I am an extremely new person to Ruby and Chef. I have been trying to wrap my head around the syntax and do some research, but I am sure as you all know unless one knows the terminology, it is hard to find what you are looking for. I have read up on Ruby code blocks, but the Chef code blocks still confuse me. I see something like this for example: log "a debug string" do level :debug end Which adds "a debug string" to the log. From what I have seen though, it seems to me like it should be

Copy file from chef client node to workstation

假装没事ソ 提交于 2019-11-28 05:31:34
问题 I would like to know how to transfer a file from a client node to a remote machine. I have checked whether there any resource available for doing this. The closest thing I found is remote_file , but it is fetching a file from remote location and transfer it to the client node. So I tried another option by writing a bash script which will perform an automated scp. But I cant able to copy the file, but the chef-client was running fine without showing any errors. Here is my script for copying

How can you use a Chef recipe to set an environment variable?

夙愿已清 提交于 2019-11-27 12:37:04
How can you use a Chef recipe to set an environment variable? I need to set an environment variable using a Chef recipe. Can you provide an example of how to accomplish this? jodell If you need an env var set strictly within the Chef process, you can use ENV['foo'] = 'bar ' since it's a ruby process. If you need to set one for an execute provider , Chef exposes an environment hash: execute 'Bootstrap the database' do cwd "#{app_dir}/current" command "#{env_cmd} rake db:drop db:create db:schema:load RAILS_ENV=#{rails_env}" environment 'HOME' => "/home/#{app_user}" user app_user action :run not

How can I change a file with Chef?

↘锁芯ラ 提交于 2019-11-27 03:50:34
I have 7 files and 1 war. I need to change values when I deploy them. I have this: ##usuario #alfresco.user=***** alfresco.user=******** ##pass #alfresco.password= sfsfs alfresco.password=sfgsf alfresco.rutaAnexos=/gthtfdh/dfgdf/cm: #atributo.type.anexo=ANEXO_INFO_OBJETO atributo.type.anexo=AN atributo.type.observaciones=OBSERVACIONES I need to comment some lines and uncomment some other lines. Then I need to make seven templates and put variables depending on the environments and create a file in the recipe. How can I do this? StephenKing By design, you don't modify files with Chef. Instead