42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/dream-ops/init/solo.rb', line 42
def init_target(target, dryrun)
if !target[:solo_installed]
if dryrun
DreamOps.ui.warn "...WOULD Install chef-solo via CINC [target=\"#{target[:host]}\"]"
else
DreamOps.ui.warn "...Installing chef-solo via CINC [target=\"#{target[:host]}\"]"
ubuntu_ver = `ssh #{@ssh_opts} #{target[:host]} "awk 'BEGIN { FS = \\"=\\" } /DISTRIB_RELEASE/ { print \\$2 }' /etc/lsb-release"`.chomp
deb_file = "cinc_17.10.0-1_amd64.deb"
cinc_url = "http://downloads.cinc.sh/files/stable/cinc/17.10.0/ubuntu/#{ubuntu_ver}/#{deb_file}"
if system("ssh #{@ssh_opts} #{target[:host]} \"wget #{cinc_url} -P /tmp\" #{@q_all}")
`ssh #{@ssh_opts} #{target[:host]} "sudo dpkg -i /tmp/#{deb_file}" #{@q_all}`
`ssh #{@ssh_opts} #{target[:host]} "sudo rm /tmp/#{deb_file}" #{@q_all}`
else
__bail_with_fatal_error(ChefSoloFailedError.new(target, cinc_url))
end
end
end
if !dryrun
`ssh #{@ssh_opts} #{target[:host]} sudo mkdir -p /var/chef/cookbooks`
`ssh #{@ssh_opts} #{target[:host]} sudo mkdir -p /var/chef/roles`
if system("ssh #{@ssh_opts} #{target[:host]} which cinc-solo #{@q_all}")
`ssh #{@ssh_opts} #{target[:host]} sudo mkdir /var/cinc`
`ssh #{@ssh_opts} #{target[:host]} sudo ln -s /var/chef/cookbooks /var/cinc/cookbooks`
`ssh #{@ssh_opts} #{target[:host]} sudo ln -s /var/chef/roles /var/cinc/roles`
end
end
if !target[:solo_json_exists]
json_path = "/var/chef/chef.json"
if dryrun
DreamOps.ui.warn "...WOULD Create boilerplate #{json_path} [target=\"#{target[:host]}\"]"
else
DreamOps.ui.warn "...Creating boilerplate #{json_path} [target=\"#{target[:host]}\"]"
`ssh #{@ssh_opts} #{target[:host]} "echo '{\n \\"run_list\\": []\n}' | sudo tee -a #{json_path}"`
end
end
if !target[:setup_role_exists]
setup_path = "/var/chef/roles/setup.json"
if dryrun
DreamOps.ui.warn "...WOULD Create boilerplate #{setup_path} [target=\"#{target[:host]}\"]"
else
DreamOps.ui.warn "...Creating boilerplate #{setup_path} [target=\"#{target[:host]}\"]"
role_contents = [
'{',
' \"name\": \"setup\",',
' \"json_class\": \"Chef::Role\",',
' \"description\": \"This role is intended for use when cookbook changes are detected\",',
' \"chef_type\": \"role\",',
' \"run_list\": []',
'}',
].join("\n")
`ssh #{@ssh_opts} #{target[:host]} "echo '#{role_contents}' | sudo tee -a #{setup_path}"`
end
end
if !target[:deploy_role_exists]
deploy_path = "/var/chef/roles/deploy.json"
if dryrun
DreamOps.ui.warn "...WOULD Create boilerplate #{deploy_path} [target=\"#{target[:host]}\"]"
else
DreamOps.ui.warn "...Creating boilerplate #{deploy_path} [target=\"#{target[:host]}\"]"
role_contents = [
'{',
' \"name\": \"deploy\",',
' \"json_class\": \"Chef::Role\",',
' \"description\": \"This role is intended for use when code changes\",',
' \"chef_type\": \"role\",',
' \"run_list\": []',
'}',
].join("\n")
`ssh #{@ssh_opts} #{target[:host]} "echo '#{role_contents}' | sudo tee -a #{deploy_path}"`
end
end
end
|