chef

updating file using 'file' chef-solo resource

陌路散爱 提交于 2019-12-05 13:32:56
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 file "/etc/profile" do owner "root" group "root" action :touch content JAVA_HOME content PATH end but

Why does the LWRP custom definition gives me undefined method for nil:NilClass

喜你入骨 提交于 2019-12-05 11:55:34
I have problem with my custom definition of this LWRP. resources : user_postgresql. actions :create, :alter default_action :create attribute :username, :kind_of => String attribute :password, :kind_of => String attribute :database_name, :kind_of => String providers : user_postgresql. def whyrun_supported? true end action :create do converge_by "Create [#{new_resource}]" do USER_NAME = new_resource.username USER_PASSWORD = new_resource.password unless (new_resource.password.nil? || new_resource.password.empty?) USER_PASSWORD = USER_NAME DATABASE_NAME = new_resource.database_name unless (new

chef ruby gem installer failing

那年仲夏 提交于 2019-12-05 10:51:33
I am trying to setup cassandra on an CentOS VM via chef and it fails with the error below. I have tried clearing out bundle caches to no avail. The recipe works on another machine but a key difference is that I ran other recipes on that machine beforehand so I suspect I am missing a chef dependency (which is why I haven't tried just fixing the packages directly). I am also terribly new to ruby so sorry if this is an obvious question. Machine config Chef: 11.4.0 ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux] gem 1.8.24 Linux somehost 2.6.32-276.el6.x86_64 #1 SMP Tue May 29 17:38:19

How to recursively change the owner and group on a directory with Chef?

倖福魔咒の 提交于 2019-12-05 09:39:10
问题 the resource_directory has only 2 actions available: create and delete I need to update the owner and group of a directory recursively. How do I do that? using a simple resource_execute ? execute "chown-data-www" do command "chown -R www-data:www-data /var/www/myfoler" user "root" action :run end 回答1: You can set the default action to nothing then have resources that may screw things up notify the perm fixer: execute "chown-data-www" do command "chown -R www-data:www-data /var/www/myfoler"

How to implement a dynamic attribute default in chef LWRP definition

梦想的初衷 提交于 2019-12-05 08:33:47
I would like to be able to define a lightweight resource with let's say 3 parameters, two of them being basic/elementary parameters and the third being a combination of these two. I would also like to provide a possibility of customization of the third parameter. For example: How to modify following code to achieve above behaviour for the full_name attribute: resource definition: actions :install attribute :name, :kind_of => String, :name_attribute => true attribute :version, :kind_of => String attribute :full_name, :kind_of => String provider definition: action :install do Chef::Log.info "#

How to check if the directory is symlink in chef

廉价感情. 提交于 2019-12-05 08:01:38
I just want to do delete directory if it is not symlnik. directory "/var/www/html/" do action :delete only_if ??? end The selected answer will not work on Windows or systems where Bash is the default interpreter. You should use a Ruby solution to be cross-platform (and faster, since there's no process spawning): directory '/var/www/html' do action :delete not_if { File.symlink?('/var/www/html') } end How about: directory "/var/www/html/" do action :delete not_if "test -L /var/www/html/" end test -L $file returns 0 (true) if $file is a symlink. 来源: https://stackoverflow.com/questions/22892284

How can I test my LWRP with ChefSpec?

大兔子大兔子 提交于 2019-12-05 07:21:29
I created my custom LWRP, but when I run the ChefSpec units test. It doesn't know my LWRP actions. Here is my resource : actions :install, :uninstall default_action :install attribute :version, :kind_of => String attribute :options, :kind_of => String Here is my provider : def whyrun_supported? true end action :install do version = @new_resource.version options = @new_resource.options e = execute "sudo apt-get install postgresql-#{version} #{options}" @new_resource.updated_by_last_action(e.updated_by_last_action?) end And here is my ChefSpec unit test: require_relative '../spec_helper'

Chef Solo error: Cookbook apt not found

﹥>﹥吖頭↗ 提交于 2019-12-05 07:21:09
Hy I'm trying to run a MongoDB recipe with Chef Solo on an Amazon EC2 Linux AMI. I've installed Omnibus, set the cookbook path in the .rb file, and the runlist in the .json file. I've copied the content of the mongodb recipe zip from github to to cookbook folder, and ran the chef-solo command. The result is below: FATAL: Chef::Exceptions::CookbookNotFound: Cookbook apt not found. If you're loading apt from another cookbook, make sure you configure the dependency in your metadata I'm pretty new to Linux too, what am I doing wrong here? The error is pretty descriptive. You likely have a cookbook

knife bootstrap windows winrm from Mac OS X workstation fails

谁说胖子不能爱 提交于 2019-12-05 05:19:18
问题 Running the command knife bootstrap windows winrm ec2box.amazonaws.com -r 'role[web]' -x Administrator -P 'mypassword' from my Mac OS X workstation produces the output below. Running it from a Windows workstation, the command successfully runs. Is there an extra step I need to take to get my Mac OS X workstation to communicate via WinRM correctly? I'm using this on Amazon's Windows Server 2012 AMI. It printed #39 everywhere on my terminal, not an artifact of Stack Overflow. WARNING: Could not

开源的自动化部署工具探索

落花浮王杯 提交于 2019-12-05 04:11:56
1 前言 即使是在传统的企业当中,日常的备份、服务器状态监控和日志,通过手动的方式来进行的效率也很低,是一种人力的浪费。因此,自动化早已是每个运维都必须掌握的看家本领。 在不同的企业中,自动化的规模、需求与实现方式都各不相同,因此在技术细节层面,运维之间很难将别的企业的方法整个套用过来。然而在很多情况下,自动化的思路是有共通之处的。 运维自动化前三阶段 ◆纯手工阶段:手工操作重复地进行软件部署和运维。 ◆脚本阶段:通过编写脚本、方便地进行软件部署和运维。 ◆工具阶段:借助第三方工具高效、方便地进行软件部署和运维。 这几个阶段是随着运维知识、经验、教训不断积累而不断演进的。而且,第2个阶段和第3个阶段可以说是齐头并进,Linux下的第三方工具虽说已经不少了,但是Linux下的脚本编写对运维工作的促进作用是绝对不可以忽视的。 在DevOps出现之前,运维工作者在工作中还是以这两种方式为主。 下面的研究,都是一些linux下开源的第三方工具,借助第三方工具高效、方便地进行软件部署和运维。 2 业界开源的自动化部署工具 2.1 chef Chef 是一款自动化服务器配置管理工具,可以对所管理的对象实行自动化配置,如系统管理,安装软件,基于ruby语言编写的。 2.1.1 Chef的架构 2.1.2 Chef的工作原理: Chef 由三大组件组成:Chef Server、Chef