Skip to content

Instantly share code, notes, and snippets.

View sawanoboly's full-sized avatar
🤷‍♂️
🙃

Yukihiko SAWANOBORI sawanoboly

🤷‍♂️
🙃
View GitHub Profile
@sawanoboly
sawanoboly / Rakefile
Created March 5, 2014 08:22
Rakefile for vagrant_with_chefzero_example
task :default => 'upload'
$stdin.sync = true
desc 'upload chef-repos to chefzero vm'
task :upload do
system('knife cookbook upload --all')
system('knife upload environments/ ')
system('knife upload roles/ ')
end
@sawanoboly
sawanoboly / apt-get_with_grub-pc.sh
Created March 28, 2014 09:43
apt-get -y upgrade without a grub-pc config prompt.
apt-get -y update
apt-get -y install debconf-utils
cat <<EOL | debconf-set-selections
grub-pc grub-pc/install_devices multiselect /dev/vda
grub-pc grub-pc/install_devices_empty boolean false
EOL
apt-get -y upgrade
@sawanoboly
sawanoboly / Pry_Console
Last active August 29, 2015 13:57
Chefの`shell_out`と`shell_out!`、違いと使い分け ref: http://qiita.com/sawanoboly/items/43bc9e15739355f9c533
> result = shell_out!('ps | grep hogehgoe')
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of ps | grep hogehgoe ----
STDOUT:
STDERR:
---- End output of ps | grep hogehgoe ----
Ran ps | grep hogehgoe returned 1
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:251:in `invalid!'
@sawanoboly
sawanoboly / chef-apply
Last active August 29, 2015 13:59
サービス名が不定のデーモンをChefのlazyで遅延処理する ref: http://qiita.com/sawanoboly/items/b7238b97012f2df486cd
# chef-apply test.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* service[test] action nothing (up to date)
* file[/tmp/hoge] action create
- update content in file /tmp/hoge from 2b795c to 04db98
--- /tmp/hoge 2014-04-15 03:13:48.000000000 +0000
+++ /tmp/.hoge20140415-4288-ulgn9f 2014-04-15 03:15:43.000000000 +0000
@@ -1,2 +1,2 @@
-2014-04-15 03:13:48 +0000
+2014-04-15 03:15:43 +0000
@sawanoboly
sawanoboly / file0.txt
Last active August 29, 2015 14:00
Rubyプロジェクトのコンフィグ読み出しでChamberを使ってみた ref: http://qiita.com/sawanoboly/items/47c799fb7390323564ad
require 'chamber'
env_confs = [
File.expand_path('../../config/environment.yml', __FILE__),
File.expand_path('../../config/environment.local.yml', __FILE__)
]
EnvSettings = Chamber.load files: env_confs
app_confs = [
@sawanoboly
sawanoboly / file3.txt
Last active August 29, 2015 14:00
serverspecとCapybaraを一緒に使う ref: http://qiita.com/sawanoboly/items/ddfcb5cac037c15a4052
# -- snip --
if c.host != host
c.ssh.close if c.ssh
c.host = host
## ここでCapybara.app_hostを設定しちゃう。
Capybara.app_host = "http://#{host}"
options = Net::SSH::Config.for(c.host)
user = options[:user] || Etc.getlogin
c.ssh = Net::SSH.start(host, user, options)
end
@sawanoboly
sawanoboly / chef-apply_stdout
Last active August 29, 2015 14:00
ChefのCronリソースがPredefined scheduling指定に対応した ref: http://qiita.com/sawanoboly/items/570711f1fd19c504474a
$ chef-client -v
Chef: 11.12.4
$ sudo chef-apply cron.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* cron[at_reboot] action create
- add crontab entry for cron[at_reboot]
@sawanoboly
sawanoboly / joyent.rb
Last active August 29, 2015 14:01
Ohai6のプラグインをOhai7のSyntaxに書き直す ref: http://qiita.com/sawanoboly/items/ca225effa6d28912624d
Ohai.plugin(:Joyent) do
%w{ sm_uuid sm_id sm_image sm_image_id sm_image_ver sm_baseimage sm_baseimage_id sm_baseimage_ver sm_pkgsrc }.each do |info|
provides "joyent/#{info}"
end
provides 'virtualization/guest_id'
depends 'os', 'platform', 'virtualization'
def collect_solaris_guestid
command = '/usr/sbin/zoneadm list -p'
curl -XPUT http://localhost:9200/_template/main_template?pretty -d ' {
"template" : "logstash-*",
"order" : 10,
"settings" : {
"index.number_of_replicas" : 0
},
"mappings" : {
"_default_" : {
"numeric_detection" : true
} }
@sawanoboly
sawanoboly / smartos.erb
Last active August 29, 2015 14:05
Knife(Opscode Chef) bootstrap template with omnibus chef for joyent smartos.
bash -c '
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
exists() {
if command -v $1 &>/dev/null
then
return 0
else
return 1
fi