chef

How to get a linux command output to chef attribute

我只是一个虾纸丫 提交于 2020-01-03 06:59:19
问题 I want to get a command output into a chef attribute. Can some one help me how to set that in execute resource or bash resource. ruby_block "something" do block do #tricky way to load this Chef::Mixin::ShellOut utilities Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut) command = 'cat #{fileName}' command_out = shell_out(command) node.set['my_attribute'] = command_out.stdout end action :create end How to use attributes in the above code.. 回答1: The answer to your question is

Chef recipe to clone several git repos to separate folders

南楼画角 提交于 2020-01-03 02:58:29
问题 I need to clone several git repositories into separate folders (i.e /var/www/repo_name ). It seems to me, I can do that with: git node['git_folder'] do repository node['git_repository'] reference "master" action :sync user "username" end But how can I give several attributes to one recipe in the role?. Can I somehow use data bags for my needs? Is there any different way? 回答1: Here is how you would accomplish it using data bags: Assuming you have the following data bag structure: data_bags git

Managing application configuration in a chef environment cookbook

纵饮孤独 提交于 2020-01-02 13:26:30
问题 I am new to chef and have been struggling to find best practices on how to configure application configuration in an environment cookbook [source #1]. The environment cookbook I'm working on should do the following: Prepare the node for a custom application deployment by creating directories, users, etc. that are specific for this deployment only. Add initialization and monitoring scripts specific for the application deployment. Define the application configuration settings. This last

How to setup Vagrant ssh agent forwarding?

我的梦境 提交于 2020-01-02 10:29:09
问题 My goal is to connect from a VirtualBox VM to another machine using the ssh key authentication. I have created the VM with Vagrant (1.0.5). I have also enabled config.ssh.forward_agent = true (as suggested in this post). Sadly, the ssh forwarding does not seem to be working. These are the steps (on fresh ubuntu with vagrant and virtualbox): Log from the host machine to VM (when I use --debug, I see that the forwarding is enabled) vagrant ssh Log from VM (ubuntu 12.04 with injected vagrant ssh

updating file using 'file' chef-solo resource

核能气质少年 提交于 2020-01-02 06:28:07
问题 i am trying to install java using chef-solo . The problem is to set the JAVA_HOME and PATH variables in /etc/profile file. I tried using 'file' resource provided by chef. here is some of my code: java_home = "export JAVA_HOME=/usr/lib/java/jdk1.7.0_05" path = "export PATH=$PATH:/usr/lib/java/jdk1.7.0_05/bin" execute "make_dir" do cwd "/usr/lib/" user "root" command "mkdir java" end execute "copy" do cwd "/usr/lib/java" user "root" command "cp -r /home/user/Downloads/jdk1* /usr/lib/java" end

updating file using 'file' chef-solo resource

两盒软妹~` 提交于 2020-01-02 06:27:07
问题 i am trying to install java using chef-solo . The problem is to set the JAVA_HOME and PATH variables in /etc/profile file. I tried using 'file' resource provided by chef. here is some of my code: java_home = "export JAVA_HOME=/usr/lib/java/jdk1.7.0_05" path = "export PATH=$PATH:/usr/lib/java/jdk1.7.0_05/bin" execute "make_dir" do cwd "/usr/lib/" user "root" command "mkdir java" end execute "copy" do cwd "/usr/lib/java" user "root" command "cp -r /home/user/Downloads/jdk1* /usr/lib/java" end

Why config files should't be changed line-by-line with Chef / Puppet?

*爱你&永不变心* 提交于 2020-01-02 01:55:25
问题 Why is changing lines in configuration file considered an anti-pattern in Chef or Puppet? It's something like bad habit, as I understood. I assume that this file-editing is done in some idempotent way and with advanced tools (augeas for example). Why is deploying the whole files, with ERB templates, considered a preferred method? You can find a lot of examples where dev-ops are suggesting usage of templates instead of file-editing. For example here, here, here, etc. 回答1: Actually there is a

How to create a virtual host with vagrant and chef

大憨熊 提交于 2020-01-01 12:40:50
问题 I've setup my first vagrant machine, with some cookbooks downloaded through knife. I am stuck with the setup of a virtual host. Here's my Vagrantfile: Vagrant.configure("2") do |config| config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "192.168.33.10" config.vm.provision :chef_solo do |chef| chef.json = { "mysql" => { "server_root_password" => "admin",

Chef - create template with dynamic variable?

谁都会走 提交于 2020-01-01 08:59:11
问题 I'm having a bit of a challenge on a Chef recipe. I'm new to Chef, so please bear with me. Step 1: My chef recipe installs Ruby Passenger, then compiles the Passenger nginx module along with Nginx. # Install passenger and nginx module bash "Install Passenger" do code <<-EOF source /usr/local/rvm/scripts/rvm gem install passenger EOF user "root" not_if { `gem list`.lines.grep(/^passenger \(.*\)/).count > 0 } end # Install passenger # Note that we have to explicitly include the RVM script

How to read cookbook file at recipe compilation time?

二次信任 提交于 2020-01-01 05:28:09
问题 This kind of thing is commonly seen in Chef recipes: %w{foo bar baz}.each do |x| file "#{x}" do content "whatever" end end But I want to read the items to loop over from a file which is kept with the cookbook, for example: File.open('files/default/blah.txt').each do |x| file "#{x}" do content "whatever" end end This works if I give the full path to blah.txt where chef-client happens to cache it, but it's not portable. It doesn't work if I write it like in the example, "hoping" that the