itamae-mitsurin 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +26 -0
- data/README.md +44 -0
- data/Rakefile +55 -0
- data/bin/itamae +5 -0
- data/bin/itamae-mitsurin +5 -0
- data/itamae-mitsurin.gemspec +35 -0
- data/lib/itamae.rb +18 -0
- data/lib/itamae/backend.rb +293 -0
- data/lib/itamae/cli.rb +86 -0
- data/lib/itamae/definition.rb +40 -0
- data/lib/itamae/ext.rb +1 -0
- data/lib/itamae/ext/specinfra.rb +39 -0
- data/lib/itamae/generators.rb +20 -0
- data/lib/itamae/generators/cookbook.rb +22 -0
- data/lib/itamae/generators/project.rb +22 -0
- data/lib/itamae/generators/role.rb +22 -0
- data/lib/itamae/generators/templates/cookbook/default.rb +0 -0
- data/lib/itamae/generators/templates/cookbook/files/.keep +0 -0
- data/lib/itamae/generators/templates/cookbook/templates/.keep +0 -0
- data/lib/itamae/generators/templates/project/Gemfile +4 -0
- data/lib/itamae/generators/templates/project/cookbooks/.keep +0 -0
- data/lib/itamae/generators/templates/project/roles/.keep +0 -0
- data/lib/itamae/generators/templates/role/default.rb +0 -0
- data/lib/itamae/generators/templates/role/files/.keep +0 -0
- data/lib/itamae/generators/templates/role/templates/.keep +0 -0
- data/lib/itamae/handler.rb +21 -0
- data/lib/itamae/handler/base.rb +40 -0
- data/lib/itamae/handler/debug.rb +10 -0
- data/lib/itamae/handler/fluentd.rb +44 -0
- data/lib/itamae/handler/json.rb +22 -0
- data/lib/itamae/handler_proxy.rb +38 -0
- data/lib/itamae/logger.rb +124 -0
- data/lib/itamae/mitsurin.rb +13 -0
- data/lib/itamae/mitsurin/cli.rb +56 -0
- data/lib/itamae/mitsurin/creators.rb +19 -0
- data/lib/itamae/mitsurin/creators/cookbook.rb +24 -0
- data/lib/itamae/mitsurin/creators/project.rb +24 -0
- data/lib/itamae/mitsurin/creators/templates/project/.rspec +2 -0
- data/lib/itamae/mitsurin/creators/templates/project/Gemfile +3 -0
- data/lib/itamae/mitsurin/creators/templates/project/Rakefile +2 -0
- data/lib/itamae/mitsurin/creators/templates/project/environments/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/environments/sample.json +7 -0
- data/lib/itamae/mitsurin/creators/templates/project/nodes/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/nodes/sample01.json +8 -0
- data/lib/itamae/mitsurin/creators/templates/project/roles/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +2 -0
- data/lib/itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/project/spec/spec_helper.rb +32 -0
- data/lib/itamae/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
- data/lib/itamae/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
- data/lib/itamae/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
- data/lib/itamae/mitsurin/itamae_task.rb +199 -0
- data/lib/itamae/mitsurin/serverspec_task.rb +110 -0
- data/lib/itamae/mitsurin/version.rb +5 -0
- data/lib/itamae/mitsurin/version.txt +1 -0
- data/lib/itamae/node.rb +74 -0
- data/lib/itamae/notification.rb +46 -0
- data/lib/itamae/recipe.rb +171 -0
- data/lib/itamae/recipe_children.rb +86 -0
- data/lib/itamae/resource.rb +73 -0
- data/lib/itamae/resource/aws_ebs_volume.rb +84 -0
- data/lib/itamae/resource/base.rb +374 -0
- data/lib/itamae/resource/directory.rb +63 -0
- data/lib/itamae/resource/execute.rb +26 -0
- data/lib/itamae/resource/file.rb +176 -0
- data/lib/itamae/resource/gem_package.rb +81 -0
- data/lib/itamae/resource/git.rb +94 -0
- data/lib/itamae/resource/group.rb +42 -0
- data/lib/itamae/resource/http_request.rb +71 -0
- data/lib/itamae/resource/link.rb +33 -0
- data/lib/itamae/resource/local_ruby_block.rb +15 -0
- data/lib/itamae/resource/package.rb +44 -0
- data/lib/itamae/resource/remote_directory.rb +84 -0
- data/lib/itamae/resource/remote_file.rb +54 -0
- data/lib/itamae/resource/service.rb +69 -0
- data/lib/itamae/resource/template.rb +53 -0
- data/lib/itamae/resource/user.rb +93 -0
- data/lib/itamae/runner.rb +124 -0
- data/spec/integration/Vagrantfile +35 -0
- data/spec/integration/default_spec.rb +226 -0
- data/spec/integration/recipes/default.rb +423 -0
- data/spec/integration/recipes/default2.rb +6 -0
- data/spec/integration/recipes/define/default.rb +6 -0
- data/spec/integration/recipes/define/files/remote_file_in_definition +1 -0
- data/spec/integration/recipes/dry_run.rb +6 -0
- data/spec/integration/recipes/files/remote_file_auto +1 -0
- data/spec/integration/recipes/hello.erb +6 -0
- data/spec/integration/recipes/hello.txt +1 -0
- data/spec/integration/recipes/included.rb +9 -0
- data/spec/integration/recipes/node.json +3 -0
- data/spec/integration/recipes/redefine.rb +20 -0
- data/spec/integration/recipes/templates/template_auto.erb +6 -0
- data/spec/integration/spec_helper.rb +42 -0
- data/spec/unit/lib/itamae/backend_spec.rb +95 -0
- data/spec/unit/lib/itamae/handler/base_spec.rb +34 -0
- data/spec/unit/lib/itamae/handler/fluentd_spec.rb +19 -0
- data/spec/unit/lib/itamae/handler_proxy_spec.rb +38 -0
- data/spec/unit/lib/itamae/handler_spec.rb +11 -0
- data/spec/unit/lib/itamae/node_spec.rb +14 -0
- data/spec/unit/lib/itamae/recipe_spec.rb +6 -0
- data/spec/unit/lib/itamae/resource/base_spec.rb +127 -0
- data/spec/unit/lib/itamae/resource_spec.rb +23 -0
- data/spec/unit/lib/itamae/runner_spec.rb +32 -0
- data/spec/unit/spec_helper.rb +23 -0
- metadata +393 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'itamae'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Itamae
|
6
|
+
class Runner
|
7
|
+
class << self
|
8
|
+
def run(recipe_files, backend_type, options)
|
9
|
+
Itamae.logger.info "Starting Itamae..."
|
10
|
+
|
11
|
+
backend = Backend.create(backend_type, options)
|
12
|
+
runner = self.new(backend, options)
|
13
|
+
runner.load_recipes(recipe_files)
|
14
|
+
runner.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :backend
|
19
|
+
attr_reader :options
|
20
|
+
attr_reader :node
|
21
|
+
attr_reader :tmpdir
|
22
|
+
attr_reader :children
|
23
|
+
attr_reader :handler
|
24
|
+
|
25
|
+
def initialize(backend, options)
|
26
|
+
@backend = backend
|
27
|
+
@options = options
|
28
|
+
|
29
|
+
prepare_handler
|
30
|
+
|
31
|
+
@node = create_node
|
32
|
+
@tmpdir = "/tmp/itamae_tmp"
|
33
|
+
@children = RecipeChildren.new
|
34
|
+
|
35
|
+
@backend.run_command(["mkdir", "-p", @tmpdir])
|
36
|
+
@backend.run_command(["chmod", "777", @tmpdir])
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_recipes(paths)
|
40
|
+
paths.each do |path|
|
41
|
+
expanded_path = File.expand_path(path)
|
42
|
+
if path.include?('::')
|
43
|
+
gem_path = Recipe.find_recipe_in_gem(path)
|
44
|
+
expanded_path = gem_path if gem_path
|
45
|
+
end
|
46
|
+
|
47
|
+
recipe = Recipe.new(self, expanded_path)
|
48
|
+
children << recipe
|
49
|
+
recipe.load
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run
|
54
|
+
if recipe_graph_file = options[:recipe_graph]
|
55
|
+
save_dependency_graph(recipe_graph_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
children.run
|
59
|
+
@backend.finalize
|
60
|
+
|
61
|
+
if profile = options[:profile]
|
62
|
+
save_profile(profile)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def dry_run?
|
67
|
+
@options[:dry_run]
|
68
|
+
end
|
69
|
+
|
70
|
+
def save_dependency_graph(path)
|
71
|
+
Itamae.logger.info "Writing recipe dependency graph to #{path}..."
|
72
|
+
open(path, 'w') do |f|
|
73
|
+
f.write(children.dependency_in_dot)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def save_profile(path)
|
78
|
+
open(path, 'w', 0600) do |f|
|
79
|
+
f.write(@backend.executed_commands.to_json)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def create_node
|
85
|
+
hash = {}
|
86
|
+
|
87
|
+
if @options[:ohai]
|
88
|
+
unless @backend.run_command("which ohai", error: false).exit_status == 0
|
89
|
+
# install Ohai
|
90
|
+
Itamae.logger.info "Installing Chef package... (to use Ohai)"
|
91
|
+
@backend.run_command("curl -L https://www.opscode.com/chef/install.sh | bash")
|
92
|
+
end
|
93
|
+
|
94
|
+
Itamae.logger.info "Loading node data via ohai..."
|
95
|
+
hash.merge!(JSON.parse(@backend.run_command("ohai").stdout))
|
96
|
+
end
|
97
|
+
|
98
|
+
if @options[:node_json]
|
99
|
+
path = File.expand_path(@options[:node_json])
|
100
|
+
Itamae.logger.info "Loading node data from #{path}..."
|
101
|
+
hash.merge!(JSON.load(open(path)))
|
102
|
+
end
|
103
|
+
|
104
|
+
if @options[:node_yaml]
|
105
|
+
path = File.expand_path(@options[:node_yaml])
|
106
|
+
Itamae.logger.info "Loading node data from #{path}..."
|
107
|
+
hash.merge!(YAML.load(open(path)) || {})
|
108
|
+
end
|
109
|
+
|
110
|
+
Node.new(hash, @backend)
|
111
|
+
end
|
112
|
+
|
113
|
+
def prepare_handler
|
114
|
+
@handler = HandlerProxy.new
|
115
|
+
(@options[:handlers] || []).each do |handler|
|
116
|
+
type = handler.delete('type')
|
117
|
+
unless type
|
118
|
+
raise "#{type} field is not set"
|
119
|
+
end
|
120
|
+
@handler.register_instance(Handler.from_type(type).new(handler))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
require 'vagrant-digitalocean'
|
4
|
+
|
5
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
6
|
+
VAGRANTFILE_API_VERSION = "2"
|
7
|
+
|
8
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
9
|
+
config.vm.define :trusty do |c|
|
10
|
+
c.vm.hostname = 'itamae-trusty'
|
11
|
+
c.vm.hostname += "-#{ENV['WERCKER_BUILD_ID']}" if ENV['WERCKER_BUILD_ID']
|
12
|
+
c.vm.provider :virtualbox do |provider, override|
|
13
|
+
override.vm.box = "ubuntu/trusty64"
|
14
|
+
override.vm.provision :shell, inline: <<-EOC
|
15
|
+
cat /etc/apt/sources.list | sed -e 's|http://[^ ]*|mirror://mirrors.ubuntu.com/mirrors.txt|g' > /tmp/sources.list
|
16
|
+
if !(diff -q /etc/apt/sources.list /tmp/sources.list); then
|
17
|
+
mv /tmp/sources.list /etc/apt/sources.list
|
18
|
+
apt-get update
|
19
|
+
fi
|
20
|
+
EOC
|
21
|
+
end
|
22
|
+
|
23
|
+
c.vm.provider :digital_ocean do |provider, override|
|
24
|
+
override.ssh.private_key_path = '~/.ssh/id_rsa.vagrant'
|
25
|
+
override.vm.box = 'digital_ocean'
|
26
|
+
override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
|
27
|
+
|
28
|
+
provider.ssh_key_name = ENV['WERCKER'] ? 'vagrant/wercker/itamae' : 'Vagrant'
|
29
|
+
provider.token = ENV['DIGITALOCEAN_TOKEN']
|
30
|
+
provider.image = 'ubuntu-14-04-x64' # ubuntu
|
31
|
+
provider.region = 'nyc3'
|
32
|
+
provider.size = '512mb'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe user("itamae") do
|
4
|
+
it { should exist }
|
5
|
+
it { should have_uid 1234 }
|
6
|
+
it { should have_home_directory '/home/itamae' }
|
7
|
+
it { should have_login_shell '/bin/dash' }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe file('/tmp/included_recipe') do
|
11
|
+
it { should be_file }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe package('dstat') do
|
15
|
+
it { should be_installed }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe package('sl') do
|
19
|
+
it { should be_installed }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe package('resolvconf') do
|
23
|
+
it { should_not be_installed }
|
24
|
+
end
|
25
|
+
|
26
|
+
%w!/tmp/remote_file /tmp/remote_file_auto!.each do |f|
|
27
|
+
describe file(f) do
|
28
|
+
it { should be_file }
|
29
|
+
its(:content) { should match(/Hello Itamae/) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe file('/tmp/directory') do
|
34
|
+
it { should be_directory }
|
35
|
+
it { should be_mode 700 }
|
36
|
+
it { should be_owned_by "itamae" }
|
37
|
+
it { should be_grouped_into "itamae" }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe file('/tmp/directory_never_exist1') do
|
41
|
+
it { should_not be_directory }
|
42
|
+
end
|
43
|
+
|
44
|
+
%w!/tmp/template /tmp/template_auto!.each do |f|
|
45
|
+
describe file(f) do
|
46
|
+
it { should be_file }
|
47
|
+
its(:content) { should match(/Hello/) }
|
48
|
+
its(:content) { should match(/Good bye/) }
|
49
|
+
its(:content) { should match(/^total memory: \d+kB$/) }
|
50
|
+
its(:content) { should match(/^uninitialized node key: $/) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe file('/tmp/file') do
|
55
|
+
it { should be_file }
|
56
|
+
its(:content) { should match(/Hello World/) }
|
57
|
+
it { should be_mode 777 }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe file('/tmp/execute') do
|
61
|
+
it { should be_file }
|
62
|
+
its(:content) { should match(/Hello Execute/) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe file('/tmp/never_exist1') do
|
66
|
+
it { should_not be_file }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe file('/tmp/never_exist2') do
|
70
|
+
it { should_not be_file }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe file('/tmp/http_request.html') do
|
74
|
+
it { should be_file }
|
75
|
+
its(:content) { should match(/"from": "itamae"/) }
|
76
|
+
end
|
77
|
+
|
78
|
+
describe file('/tmp/http_request_delete.html') do
|
79
|
+
it { should be_file }
|
80
|
+
its(:content) { should match(/"from": "itamae"/) }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe file('/tmp/http_request_post.html') do
|
84
|
+
it { should be_file }
|
85
|
+
its(:content) do
|
86
|
+
should match(/"from": "itamae"/)
|
87
|
+
should match(/"love": "sushi"/)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe file('/tmp/http_request_put.html') do
|
92
|
+
it { should be_file }
|
93
|
+
its(:content) do
|
94
|
+
should match(/"from": "itamae"/)
|
95
|
+
should match(/"love": "sushi"/)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe file('/tmp/http_request_headers.html') do
|
100
|
+
it { should be_file }
|
101
|
+
its(:content) { should match(/"User-Agent": "Itamae"/) }
|
102
|
+
end
|
103
|
+
|
104
|
+
describe file('/tmp/http_request_redirect.html') do
|
105
|
+
it { should be_file }
|
106
|
+
its(:content) { should match(/"from": "itamae"/) }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe file('/tmp/notifies') do
|
110
|
+
it { should be_file }
|
111
|
+
its(:content) { should eq("2431") }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe file('/tmp/subscribes') do
|
115
|
+
it { should be_file }
|
116
|
+
its(:content) { should eq("2431") }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe file('/tmp/cron_stopped') do
|
120
|
+
it { should be_file }
|
121
|
+
its(:content) do
|
122
|
+
expect(subject.content.lines.size).to eq 1
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe file('/tmp/cron_running') do
|
127
|
+
it { should be_file }
|
128
|
+
its(:content) do
|
129
|
+
expect(subject.content.lines.size).to eq 2
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe file('/tmp-link') do
|
134
|
+
it { should be_linked_to '/tmp' }
|
135
|
+
its(:content) do
|
136
|
+
expect(subject.content.lines.size).to eq 0
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe file('/tmp-link-force') do
|
141
|
+
it { should be_linked_to '/tmp' }
|
142
|
+
end
|
143
|
+
|
144
|
+
describe command('cd /tmp/git_repo && git rev-parse HEAD') do
|
145
|
+
its(:stdout) { should match(/3116e170b89dc0f7315b69c1c1e1fd7fab23ac0d/) }
|
146
|
+
end
|
147
|
+
|
148
|
+
describe command('cd /tmp/git_repo_submodule/empty_repo && cat README.md') do
|
149
|
+
its(:stdout) { should match(/Empty Repo/) }
|
150
|
+
end
|
151
|
+
|
152
|
+
describe file('/tmp/created_by_itamae_user') do
|
153
|
+
it { should be_file }
|
154
|
+
it { should be_owned_by 'itamae' }
|
155
|
+
its(:content) { should eq("/home/itamae\n/home/itamae") }
|
156
|
+
end
|
157
|
+
|
158
|
+
describe file('/tmp/created_in_default2') do
|
159
|
+
it { should be_file }
|
160
|
+
end
|
161
|
+
|
162
|
+
describe file('/tmp/never_exist3') do
|
163
|
+
it { should_not be_file }
|
164
|
+
end
|
165
|
+
|
166
|
+
describe file('/tmp/never_exist4') do
|
167
|
+
it { should_not be_file }
|
168
|
+
end
|
169
|
+
|
170
|
+
describe file('/tmp/created_in_redefine') do
|
171
|
+
it { should be_file }
|
172
|
+
its(:content) { should match(/first/) }
|
173
|
+
end
|
174
|
+
|
175
|
+
describe command('gem list') do
|
176
|
+
its(:stdout) { should include('tzinfo (1.2.2, 1.1.0)') }
|
177
|
+
end
|
178
|
+
|
179
|
+
describe command('ri Bundler') do
|
180
|
+
its(:stderr) { should eq("Nothing known about Bundler\n") }
|
181
|
+
end
|
182
|
+
|
183
|
+
describe file('/tmp/created_by_definition') do
|
184
|
+
it { should be_file }
|
185
|
+
its(:content) { should eq("name:name,key:value,message:Hello, Itamae\n") }
|
186
|
+
end
|
187
|
+
|
188
|
+
describe file('/tmp/remote_file_in_definition') do
|
189
|
+
it { should be_file }
|
190
|
+
its(:content) { should eq("definition_example\n") }
|
191
|
+
end
|
192
|
+
|
193
|
+
describe file('/tmp/multi_delayed_notifies') do
|
194
|
+
it { should be_file }
|
195
|
+
its(:content) { should eq("1\n2\n3\n4\n") }
|
196
|
+
end
|
197
|
+
|
198
|
+
describe file('/tmp/multi_immediately_notifies') do
|
199
|
+
it { should be_file }
|
200
|
+
its(:content) { should eq("1\n2\n3\n4\n") }
|
201
|
+
end
|
202
|
+
|
203
|
+
describe file('/tmp/file_edit_sample') do
|
204
|
+
it { should be_file }
|
205
|
+
its(:content) { should eq("Hello, Itamae") }
|
206
|
+
it { should be_mode 400 }
|
207
|
+
it { should be_owned_by "itamae2" }
|
208
|
+
it { should be_grouped_into "itamae2" }
|
209
|
+
end
|
210
|
+
|
211
|
+
describe file('/home/itamae2') do
|
212
|
+
it { should be_directory }
|
213
|
+
it { should be_owned_by "itamae2" }
|
214
|
+
it { should be_grouped_into "itamae2" }
|
215
|
+
end
|
216
|
+
|
217
|
+
describe file('/tmp/file_create_without_content') do
|
218
|
+
its(:content) { should eq("Hello, World") }
|
219
|
+
it { should be_mode 600 }
|
220
|
+
it { should be_owned_by "itamae" }
|
221
|
+
it { should be_grouped_into "itamae" }
|
222
|
+
end
|
223
|
+
|
224
|
+
describe file('/tmp/file_edit_notifies') do
|
225
|
+
its(:content) { should eq("1") }
|
226
|
+
end
|
@@ -0,0 +1,423 @@
|
|
1
|
+
node.reverse_merge!({
|
2
|
+
message: "Hello, Itamae"
|
3
|
+
})
|
4
|
+
|
5
|
+
execute 'apt-get update'
|
6
|
+
execute 'deluser --remove-home itamae2' do
|
7
|
+
only_if "id itamae2"
|
8
|
+
end
|
9
|
+
|
10
|
+
include_recipe "./included.rb"
|
11
|
+
include_recipe "./included.rb" # including the same recipe is expected to be skipped.
|
12
|
+
|
13
|
+
user "create itamae user" do
|
14
|
+
uid 123
|
15
|
+
username "itamae"
|
16
|
+
password "$1$ltOY8bZv$iZ57f1KAp8jwKViNm3pze."
|
17
|
+
home '/home/foo'
|
18
|
+
shell '/bin/sh'
|
19
|
+
end
|
20
|
+
|
21
|
+
user "update itamae user" do
|
22
|
+
uid 1234
|
23
|
+
username "itamae"
|
24
|
+
password "$1$TQz9gPMl$nHYrsA5W2ZdZ0Yn021BQH1"
|
25
|
+
home '/home/itamae'
|
26
|
+
shell '/bin/dash'
|
27
|
+
end
|
28
|
+
|
29
|
+
directory "/home/itamae" do
|
30
|
+
mode "755"
|
31
|
+
owner "itamae"
|
32
|
+
group "itamae"
|
33
|
+
end
|
34
|
+
|
35
|
+
user "create itamae2 user with create home directory" do
|
36
|
+
username "itamae2"
|
37
|
+
create_home true
|
38
|
+
home "/home/itamae2"
|
39
|
+
shell "/bin/sh"
|
40
|
+
end
|
41
|
+
|
42
|
+
######
|
43
|
+
|
44
|
+
package 'dstat' do
|
45
|
+
action :install
|
46
|
+
end
|
47
|
+
|
48
|
+
package 'sl' do
|
49
|
+
version '3.03-17'
|
50
|
+
end
|
51
|
+
|
52
|
+
package 'resolvconf' do
|
53
|
+
action :remove
|
54
|
+
end
|
55
|
+
|
56
|
+
######
|
57
|
+
|
58
|
+
package "ruby"
|
59
|
+
|
60
|
+
gem_package 'tzinfo' do
|
61
|
+
version '1.1.0'
|
62
|
+
end
|
63
|
+
|
64
|
+
gem_package 'tzinfo' do
|
65
|
+
version '1.2.2'
|
66
|
+
end
|
67
|
+
|
68
|
+
gem_package 'bundler' do
|
69
|
+
options ['--no-ri', '--no-rdoc']
|
70
|
+
end
|
71
|
+
|
72
|
+
######
|
73
|
+
|
74
|
+
execute "echo -n > /tmp/notifies"
|
75
|
+
|
76
|
+
execute "echo -n 1 >> /tmp/notifies" do
|
77
|
+
action :nothing
|
78
|
+
end
|
79
|
+
|
80
|
+
execute "echo -n 2 >> /tmp/notifies" do
|
81
|
+
notifies :run, "execute[echo -n 1 >> /tmp/notifies]"
|
82
|
+
end
|
83
|
+
|
84
|
+
execute "echo -n 3 >> /tmp/notifies" do
|
85
|
+
action :nothing
|
86
|
+
end
|
87
|
+
|
88
|
+
execute "echo -n 4 >> /tmp/notifies" do
|
89
|
+
notifies :run, "execute[echo -n 3 >> /tmp/notifies]", :immediately
|
90
|
+
end
|
91
|
+
|
92
|
+
######
|
93
|
+
|
94
|
+
execute "echo -n > /tmp/subscribes"
|
95
|
+
|
96
|
+
execute "echo -n 1 >> /tmp/subscribes" do
|
97
|
+
action :nothing
|
98
|
+
subscribes :run, "execute[echo -n 2 >> /tmp/subscribes]"
|
99
|
+
end
|
100
|
+
|
101
|
+
execute "echo -n 2 >> /tmp/subscribes"
|
102
|
+
|
103
|
+
execute "echo -n 3 >> /tmp/subscribes" do
|
104
|
+
action :nothing
|
105
|
+
subscribes :run, "execute[echo -n 4 >> /tmp/subscribes]", :immediately
|
106
|
+
end
|
107
|
+
|
108
|
+
execute "echo -n 4 >> /tmp/subscribes"
|
109
|
+
|
110
|
+
######
|
111
|
+
|
112
|
+
remote_file "/tmp/remote_file" do
|
113
|
+
source "hello.txt"
|
114
|
+
end
|
115
|
+
|
116
|
+
remote_file "/tmp/remote_file_auto" do
|
117
|
+
source :auto
|
118
|
+
end
|
119
|
+
|
120
|
+
######
|
121
|
+
|
122
|
+
directory "/tmp/directory" do
|
123
|
+
mode "700"
|
124
|
+
owner "itamae"
|
125
|
+
group "itamae"
|
126
|
+
end
|
127
|
+
|
128
|
+
directory "/tmp/directory_never_exist1" do
|
129
|
+
action :create
|
130
|
+
end
|
131
|
+
|
132
|
+
directory "/tmp/directory_never_exist1" do
|
133
|
+
action :delete
|
134
|
+
end
|
135
|
+
|
136
|
+
template "/tmp/template" do
|
137
|
+
source "hello.erb"
|
138
|
+
variables goodbye: "Good bye"
|
139
|
+
end
|
140
|
+
|
141
|
+
template "/tmp/template_auto" do
|
142
|
+
source :auto
|
143
|
+
variables goodbye: "Good bye"
|
144
|
+
end
|
145
|
+
|
146
|
+
file "/tmp/file" do
|
147
|
+
content "Hello World"
|
148
|
+
mode "777"
|
149
|
+
end
|
150
|
+
|
151
|
+
execute "echo 'Hello Execute' > /tmp/execute"
|
152
|
+
|
153
|
+
file "/tmp/never_exist1" do
|
154
|
+
only_if "exit 1"
|
155
|
+
end
|
156
|
+
|
157
|
+
file "/tmp/never_exist2" do
|
158
|
+
not_if "exit 0"
|
159
|
+
end
|
160
|
+
|
161
|
+
######
|
162
|
+
|
163
|
+
http_request "/tmp/http_request.html" do
|
164
|
+
url "https://httpbin.org/get?from=itamae"
|
165
|
+
end
|
166
|
+
|
167
|
+
http_request "/tmp/http_request_delete.html" do
|
168
|
+
action :delete
|
169
|
+
url "https://httpbin.org/delete?from=itamae"
|
170
|
+
end
|
171
|
+
|
172
|
+
http_request "/tmp/http_request_post.html" do
|
173
|
+
action :post
|
174
|
+
message "love=sushi"
|
175
|
+
url "https://httpbin.org/post?from=itamae"
|
176
|
+
end
|
177
|
+
|
178
|
+
http_request "/tmp/http_request_put.html" do
|
179
|
+
action :put
|
180
|
+
message "love=sushi"
|
181
|
+
url "https://httpbin.org/put?from=itamae"
|
182
|
+
end
|
183
|
+
|
184
|
+
http_request "/tmp/http_request_headers.html" do
|
185
|
+
headers "User-Agent" => "Itamae"
|
186
|
+
url "https://httpbin.org/get"
|
187
|
+
end
|
188
|
+
|
189
|
+
http_request "/tmp/http_request_redirect.html" do
|
190
|
+
redirect_limit 1
|
191
|
+
url "https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org%2Fget%3Ffrom%3Ditamae"
|
192
|
+
end
|
193
|
+
|
194
|
+
######
|
195
|
+
|
196
|
+
service "cron" do
|
197
|
+
action :stop
|
198
|
+
end
|
199
|
+
|
200
|
+
execute "ps -C cron > /tmp/cron_stopped; true"
|
201
|
+
|
202
|
+
service "cron" do
|
203
|
+
action :start
|
204
|
+
end
|
205
|
+
|
206
|
+
execute "ps -C cron > /tmp/cron_running; true"
|
207
|
+
|
208
|
+
######
|
209
|
+
|
210
|
+
package "nginx" do
|
211
|
+
options "--force-yes"
|
212
|
+
end
|
213
|
+
|
214
|
+
service "nginx" do
|
215
|
+
action [:enable, :start]
|
216
|
+
end
|
217
|
+
|
218
|
+
execute "test -f /etc/rc3.d/S20nginx" # test
|
219
|
+
execute "test $(ps h -C nginx | wc -l) -gt 0" # test
|
220
|
+
|
221
|
+
service "nginx" do
|
222
|
+
action [:disable, :stop]
|
223
|
+
end
|
224
|
+
|
225
|
+
execute "test ! -f /etc/rc3.d/S20nginx" # test
|
226
|
+
execute "test $(ps h -C nginx | wc -l) -eq 0" # test
|
227
|
+
|
228
|
+
######
|
229
|
+
|
230
|
+
link "/tmp-link" do
|
231
|
+
to "/tmp"
|
232
|
+
end
|
233
|
+
|
234
|
+
execute "touch /tmp-link-force"
|
235
|
+
link "/tmp-link-force" do
|
236
|
+
to "/tmp"
|
237
|
+
force true
|
238
|
+
end
|
239
|
+
|
240
|
+
#####
|
241
|
+
|
242
|
+
local_ruby_block "greeting" do
|
243
|
+
block do
|
244
|
+
Itamae.logger.info "板前"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
#####
|
249
|
+
|
250
|
+
package "git"
|
251
|
+
|
252
|
+
git "/tmp/git_repo" do
|
253
|
+
repository "https://github.com/ryotarai/infrataster.git"
|
254
|
+
revision "v0.1.0"
|
255
|
+
end
|
256
|
+
|
257
|
+
git "/tmp/git_repo_submodule" do
|
258
|
+
repository "https://github.com/mmasaki/fake_repo_including_submodule.git"
|
259
|
+
recursive true
|
260
|
+
end
|
261
|
+
|
262
|
+
#####
|
263
|
+
|
264
|
+
execute "echo -n \"$HOME\n$(pwd)\" > /tmp/created_by_itamae_user" do
|
265
|
+
user "itamae"
|
266
|
+
end
|
267
|
+
|
268
|
+
#####
|
269
|
+
|
270
|
+
execute "echo 'notify to resource in default2.rb'" do
|
271
|
+
notifies :create, "file[put file in default2.rb]"
|
272
|
+
end
|
273
|
+
|
274
|
+
#####
|
275
|
+
|
276
|
+
file "/tmp/never_exist3" do
|
277
|
+
action :create
|
278
|
+
end
|
279
|
+
|
280
|
+
file "/tmp/never_exist3" do
|
281
|
+
action :delete
|
282
|
+
end
|
283
|
+
|
284
|
+
#####
|
285
|
+
|
286
|
+
include_recipe "define/default.rb"
|
287
|
+
|
288
|
+
definition_example "name" do
|
289
|
+
key 'value'
|
290
|
+
end
|
291
|
+
|
292
|
+
#####
|
293
|
+
|
294
|
+
file "/tmp/never_exist4" do
|
295
|
+
action :nothing
|
296
|
+
end
|
297
|
+
|
298
|
+
file "/tmp/file1" do
|
299
|
+
content "Hello, World"
|
300
|
+
end
|
301
|
+
|
302
|
+
file "/tmp/file1" do
|
303
|
+
content "Hello, World"
|
304
|
+
notifies :create, "file[/tmp/never_exist4]"
|
305
|
+
end
|
306
|
+
|
307
|
+
#####
|
308
|
+
|
309
|
+
file "/tmp/file_create_without_content" do
|
310
|
+
content "Hello, World"
|
311
|
+
end
|
312
|
+
|
313
|
+
file "/tmp/file_create_without_content" do
|
314
|
+
owner "itamae"
|
315
|
+
group "itamae"
|
316
|
+
mode "600"
|
317
|
+
end
|
318
|
+
|
319
|
+
#####
|
320
|
+
|
321
|
+
execute 'true' do
|
322
|
+
verify 'true'
|
323
|
+
end
|
324
|
+
|
325
|
+
#####
|
326
|
+
|
327
|
+
execute 'echo 1 > /tmp/multi_delayed_notifies' do
|
328
|
+
notifies :run, "execute[echo 2 >> /tmp/multi_delayed_notifies]"
|
329
|
+
end
|
330
|
+
|
331
|
+
execute 'echo 2 >> /tmp/multi_delayed_notifies' do
|
332
|
+
action :nothing
|
333
|
+
notifies :run, "execute[echo 3 >> /tmp/multi_delayed_notifies]"
|
334
|
+
end
|
335
|
+
|
336
|
+
execute 'echo 3 >> /tmp/multi_delayed_notifies' do
|
337
|
+
action :nothing
|
338
|
+
notifies :run, "execute[echo 4 >> /tmp/multi_delayed_notifies]"
|
339
|
+
end
|
340
|
+
|
341
|
+
execute 'echo 4 >> /tmp/multi_delayed_notifies' do
|
342
|
+
action :nothing
|
343
|
+
end
|
344
|
+
|
345
|
+
#####
|
346
|
+
|
347
|
+
execute 'echo 1 > /tmp/multi_immediately_notifies' do
|
348
|
+
notifies :run, "execute[echo 2 >> /tmp/multi_immediately_notifies]", :immediately
|
349
|
+
end
|
350
|
+
|
351
|
+
execute 'echo 2 >> /tmp/multi_immediately_notifies' do
|
352
|
+
action :nothing
|
353
|
+
notifies :run, "execute[echo 3 >> /tmp/multi_immediately_notifies]", :immediately
|
354
|
+
end
|
355
|
+
|
356
|
+
execute 'echo 3 >> /tmp/multi_immediately_notifies' do
|
357
|
+
action :nothing
|
358
|
+
notifies :run, "execute[echo 4 >> /tmp/multi_immediately_notifies]", :immediately
|
359
|
+
end
|
360
|
+
|
361
|
+
execute 'echo 4 >> /tmp/multi_immediately_notifies' do
|
362
|
+
action :nothing
|
363
|
+
end
|
364
|
+
|
365
|
+
#####
|
366
|
+
|
367
|
+
file '/tmp/file_edit_sample' do
|
368
|
+
content 'Hello, world'
|
369
|
+
owner 'itamae'
|
370
|
+
group 'itamae'
|
371
|
+
mode '444'
|
372
|
+
end
|
373
|
+
|
374
|
+
file '/tmp/file_edit_sample' do
|
375
|
+
action :edit
|
376
|
+
owner 'itamae2'
|
377
|
+
group 'itamae2'
|
378
|
+
mode '400'
|
379
|
+
block do |content|
|
380
|
+
content.gsub!('world', 'Itamae')
|
381
|
+
end
|
382
|
+
notifies :run, "execute[echo -n 1 > /tmp/file_edit_notifies]"
|
383
|
+
end
|
384
|
+
|
385
|
+
execute 'echo -n 1 > /tmp/file_edit_notifies' do
|
386
|
+
action :nothing
|
387
|
+
end
|
388
|
+
|
389
|
+
###
|
390
|
+
|
391
|
+
unless run_command("echo -n Hello").stdout == "Hello"
|
392
|
+
raise "run_command in a recipe failed"
|
393
|
+
end
|
394
|
+
|
395
|
+
define :run_command_in_definition do
|
396
|
+
unless run_command("echo -n Hello").stdout == "Hello"
|
397
|
+
raise "run_command in a definition failed"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
execute "echo Hello" do
|
402
|
+
unless run_command("echo -n Hello").stdout == "Hello"
|
403
|
+
raise "run_command in a resource failed"
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
local_ruby_block 'execute run_command' do
|
408
|
+
block do
|
409
|
+
unless run_command("echo -n Hello").stdout == "Hello"
|
410
|
+
raise "run_command in local_ruby_block failed"
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
###
|
416
|
+
|
417
|
+
v1 = node.memory.total
|
418
|
+
v2 = node[:memory][:total]
|
419
|
+
v3 = node['memory']['total']
|
420
|
+
|
421
|
+
unless v1 == v2 && v2 == v3 && v1 =~ /\A\d+kB\z/
|
422
|
+
raise "failed to fetch host inventory value (#{v1}, #{v2}, #{v3})"
|
423
|
+
end
|