Articles of ruby

在Chef中组织代码:库,类和资源

我对厨师和Ruby都是新手,我正在实施一些脚本来学习它们。 现在,我正面临着如何组织我的代码的问题:我已经在库目录中创build了一个类,并且使用了自定义名称空间来维护顺序。 这是我的文件的一个简化的例子: # ~/chef-repo/cookbooks/mytest/libraries/MyTools.rb module Chef::Recipe::EP class MyTools def self.print_something( text ) puts "This is my text: #{text}" end def self.copy_file( dir, file ) cookbook_file "#{dir}/#{file}" do source "#{dir}/#{file}" end end end end 从我的食谱我称这两种方法: # ~/chef-repo/cookbooks/mytest/recipes/default.rb EP::MyTools.print_something "Hello World!" EP::MyTools.copy_file "/etc", "passwd" print_something工作正常,但与copy_file我得到这个错误: undefined method `cookbook_file' for Chef::Recipe::EP::FileTools:Class 我很清楚,我不知道如何在厨师里创build图书馆,或者我不知道一些基本的假设。 任何人都可以帮我吗? 我正在寻找这个问题的解决scheme(组织我的代码,库,在类中使用资源),或者更好的,一个好的厨师文档,因为我发现文档非常缺乏清晰和杂乱无章,所以通过它的研究是一个痛苦。

无法在端口80上运行webrick

我试图弄清楚如何将abcd:3000指向我的域名。 这里,abcd是我的IP地址。 按照这个post: 如何使用DNS /主机名或其他方式parsing到特定的IP:端口 我得到的印象是,我需要设置Webrick在80端口,因为这是默认的端口,因此我可以将abcd映射到我的域名,mydomain.org将到达我的网站。 这是一个正确的假设,还是我以错误的方式去做? 无论如何,我不能让Webrick使用端口80,我得到以下错误: WARN TCPServer Error: Permission denied – bind(2) 检查端口80上的侦听器: $ netstat -tlnp (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State […]

重新加载傀儡gem提供者来源

所以我在“master”节点puppettentmaster上有了Puppet Enterprise 2.7。 在开发在“客户”节点上安装Ruby 2.0的新配方时,我注意到如果我强制客户端开始使用gem 2.0,我会遇到以下错误: err: /Stage[main]/_ruby::Mysql_gem/Package[mysql]/ensure: change from absent to 2.8.1 failed: Could not update: Execution of '/usr/bin/gem install -v 2.8.1 –include-dependencies –no-rdoc –no-ri mysql' returned 1: ERROR: While executing gem … (OptionParser::InvalidOption) invalid option: –include-dependencies at /etc/puppetlabs/puppet/environments/ci/modules/_ruby/manifests/mysql_gem.pp:29 我追踪到–include-dependencies到https://github.com/puppetlabs/puppet/commit/2284e837939628f81149e62fdc0f314ff077a776 ,它已经被删除,所以我从我的Puppet提供程序代码在主/opt/puppet/lib/site_ruby/1.8/puppet/provider/package/gem.rb : def install(useversion = true) command = [command(:gemcmd), "install"] command << "-v" << […]

Fedora 20上的Openshift起源的ruby问题

检查bundle依赖性时遇到一些问题 cd /var/www/openshift/broker bundle –local 这是错误信息, Bundler could not find compatible versions for gem "activesupport": In Gemfile: openshift-origin-controller (>= 0) ruby depends on activesupport (~> 3.2.8) ruby rails (>= 0) ruby depends on activesupport (4.0.0) 这是我所有的gem名单 activesupport (4.0.0, 3.2.8, 3.1.0) … openshift-origin-admin-console (1.17.0.1) openshift-origin-auth-mongo (1.15.1.1) openshift-origin-auth-remote-user (1.17.1.1) openshift-origin-common (1.18.0.2) openshift-origin-controller (1.18.0.1) openshift-origin-dns-avahi (1.10.2.2) openshift-origin-dns-nsupdate (1.15.1.2) […]

厨师/ Ruby:使用“每做”块variables与节点属性

厨师11.10.4环境在AWS Opsworks中运行。 我不知道如何通过节点属性node['aws-tag'][#{lyr}]传递下面的“each do”块variables的值“lyr”? 下面的代码块在02-06行而不是在07-14行。 [01] include_recipe "aws" [02] unless node['aws-tag']['tags'].empty? || node['aws-tag']['tags'].nil? [03] aws_resource_tag node['ec2']['instance_id'] do [04] tags(node['aws-tag']['tags']) [05] action :update [06] end [07] node['opsworks']['instance']['layers'].each do |lyr| [08] unless node['aws-tag'][#{lyr}].empty? || node['aws-tag'][#{lyr}].nil? [09] aws_resource_tag node['ec2']['instance_id'] do [10] tags(node['aws-tag'][#{lyr}]) [11] action :update [12] end [13] end [14] end [15] end 下面是chef-shell的结果,显示了上面代码中引用的属性的值: chef> node ['opsworks'] ['instance'] […]

在手动安装ruby 1.8之后安装rubygems

我已经在Ubuntu 14.04上成功安装了Ruby 1.8.7,通过下载软件包,在本地构build和安装。 命令ruby -v按预期的方式输出Ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-Linux] ,这与运行Ubuntu 12.04的另一台服务器上的输出相同,我的应用程序按预期工作。 Ubuntu 14.04上的which ruby的输出是/usr/local/bin/ruby /usr/bin/ruby ,Ubuntu 12.04上的/usr/bin/ruby 。 这给我的印象是安装了Ruby 1.8(这是我的应用程序需要)。 但是,当我尝试安装导轨gem: gem install rails (以root身份login;我还以root身份安装了ruby),出现以下错误: The program 'gem' can be found in the following packages: * ruby * rubygems Try: apt-get install <selected package> 当运行apt-get install ruby会解决这个问题,它会安装ruby 1.9.x,这不是我需要的版本。 我已经安装了如上所述的所需版本。 运行apt-get install ruby1.8 ,它将在Ubuntu 12.04上运行,在14.04上抛出一个错误,因为ruby1.8已经有点过时了,并且已经从官方的ubuntu […]

麻烦启动Snorby / Ruby依赖项问题

我试图在CentOS 6.6机器上安装Snorby,并不断得到与ruby和我的Gemfile的问题。 我相信我要么编辑我的Gemfile,要么与安装path有关。 任何帮助将非常感激。 bundle exec rake snorby:setup 错误信息 /var/www/html/snorby/vendor/bundle/ruby/1.9.1/bundler/gems/snorby_cas_authenticatable-/devise_cas_authenticatable.gemspec的gemspec无效。 validation错误是 duplicate dependency on devise (>= 1.0.6), (>= 0) use: add_runtime_dependency 'devise', '>= 1.0.6', '>= 0'

如何获得一个EC实例的静态IP? 或者,如何使用

我只是在Amazon AWS上设置我们的Rails应用程序。 我们有2个EC2实例,一个用于Rails应用程序,另一个用于Redis。 然后是Amazon RDS for MySQL。 当我将Rails应用程序连接到Redis时,需要设置包含IP地址的Redis URL。 但是,如果我重新启动Redis实例,其IP地址将会更改,并且我input到Redis的Rails应用程序的Redis URL IP将不起作用(因为重新启动Redis实例后会生成新的IP)。 如何处理这种行为? 如何在重新启动时避免“丢失”EC2实例? 亚马逊RDS也是如此 – 这是我在database.yml设置主机的方式: host: myapp-production.cg4mxcg62ca0.us-west-2.rds.amazonaws.com 先谢谢你。

在CEntOS 6.7上的r10k,有没有人取得这个壮举?

你们知道如何在一个使用Puppet 3.6的CEntOS 6.7服务器上正确运行r10k吗? 这个矛盾呢? 我检查了r10k源代码的需求列表: https : //github.com/puppetlabs/r10k#requirements 看起来它需要Ruby 1.9。 很公平。 但… $ facter rubysitedir rubyversion rubysitedir => /usr/lib/ruby/site_ruby/1.8 rubyversion => 1.8 因此开始了对传说中的Ruby的不屑的追求。 第三方存储库 但大多数第三方回购不提供CEntOS 6.7的Ruby 1.9。 https://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/repoview/letter_r.group.html 🙁 https://dl.fedoraproject.org/pub/epel/6/x86_64/ 我没有正确安装我find的一个软件包,在Remi的回购中 ,由于缺lessmockbuild用户而失败。 我认为只有从源头上构build才是必要的。 ruby“经理人” 我安装了RVM。 然而,这需要glibc = 2.12-1.166.el6_7.7 ,我的系统没有这个特定的版本可用(出于很好的理由)。 无论如何,这只会对特定用户有效。 如果安装了RVM,需要使用Ruby的系统用户可能会感到奇怪。 rbenv ,可能减轻了这个问题,给了我同样的关于glibc的guff: $ mkdir ~/.tmp && export TMPDIR=~/.tmp && rbenv install 1.9.3-p551 ## How […]

App Engine Ruby flex环境app.yaml忽略了env_variables RAILS_ENV

我们使用GAE与Ruby灵活的环境,我们正在试图部署一个rails应用程序与阶段configuration(即RAILS_ENV = staging)。 根据https://cloud.google.com/appengine/docs/flexible/ruby/configuring-your-app-with-app-yaml,我们应该能够设置RAILS_ENVconfigurationapp.yaml的值: env_variables: RAILS_ENV: 'staging' 但是,当我们运行: gcloud app deploy 生成一个(临时的)Dockerfile # Temporary. Will be moved to base image later. ENV RACK_ENV=production \ RAILS_ENV=production \ RAILS_SERVE_STATIC_FILES=true 这会导致在PRODUCTION环境中进行部署(RAILS_ENV的默认值)。 这是一个错误还是我错过了什么?