Skip to content

Commit c1f4dc5

Browse files
author
Gabriel Monroy
committed
pre-install required etcd gem before knife bootstrap using template-file option
1 parent b467998 commit c1f4dc5

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

cm/chef.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CHEF_INSTALL_TYPE = 'gems'
2222
CHEF_RUBY_VERSION = '1.9.1'
2323
CHEF_ENVIRONMENT = '_default'
24-
CHEF_CLIENT_VERSION = '11.6.2'
24+
CHEF_CLIENT_VERSION = '11.8.2'
2525

2626
# load chef config using CHEF_CONFIG_PATH
2727
try:
@@ -49,6 +49,14 @@
4949
_valid_pem_path = os.path.join(CHEF_CONFIG_PATH, 'validation.pem')
5050
CHEF_VALIDATION_KEY = subprocess.check_output(
5151
['/bin/cat', _valid_pem_path]).strip('\n')
52+
# write out knife template
53+
if not os.path.exists('.chef'):
54+
os.mkdir('.chef')
55+
_template_src = os.path.abspath(os.path.join(__file__, '..', 'ubuntu12.04-gems.erb'))
56+
with open(_template_src) as src:
57+
_knife_template = os.path.abspath(os.path.join('.chef', 'knife-template.erb'))
58+
with open(_knife_template, 'w') as f:
59+
f.write(src.read())
5260
except Exception as err:
5361
msg = "Failed to auto-configure Chef -- {}".format(err)
5462
if os.environ.get('READTHEDOCS'):
@@ -91,6 +99,7 @@ def bootstrap_node(node):
9199
# build knife bootstrap command
92100
args = ['knife', 'bootstrap', node['fqdn']]
93101
args.extend(['--config', '/etc/chef/client.rb'])
102+
args.extend(['--template-file', '.chef/knife-template.erb'])
94103
args.extend(['--identity-file', pk_path])
95104
args.extend(['--node-name', node['id']])
96105
args.extend(['--sudo', '--ssh-user', node['ssh_username']])
@@ -103,14 +112,13 @@ def bootstrap_node(node):
103112
args.extend(['|', 'tee', output_path])
104113
# TODO: figure out why home isn't being set correctly for knife exec
105114
env = os.environ.copy()
106-
env['HOME'] = '/opt/deis'
115+
env['HOME'] = '/var/lib/deis'
107116
# execute knife bootstrap
108117
p = subprocess.Popen(' '.join(args), env=env, shell=True)
109118
rc = p.wait()
110119
# always print knife output
111120
with open(output_path) as f:
112-
output = f.read()
113-
print(output)
121+
output = str(f.read())
114122
# raise an exception if bootstrap failed
115123
if rc != 0 or 'incorrect password' in output:
116124
raise RuntimeError('Node Bootstrap Error:\n' + output)

cm/ubuntu12.04-gems.erb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
bash -c '
2+
<%= "export http_proxy=\"#{knife_config[:bootstrap_proxy]}\"" if knife_config[:bootstrap_proxy] -%>
3+
4+
if [ ! -f /usr/bin/chef-client ]; then
5+
aptitude update >/dev/null 2>&1
6+
aptitude install -yq ruby ruby1.8-dev build-essential wget libruby1.8 rubygems >/dev/null 2>&1
7+
fi
8+
9+
gem update --no-rdoc --no-ri >/dev/null 2>&1
10+
gem install ohai --no-rdoc --no-ri >/dev/null 2>&1
11+
gem install chef --no-rdoc --no-ri <%= bootstrap_version_string %> >/dev/null 2>&1
12+
13+
# install gems required at load-time
14+
gem install etcd --no-rdoc --no-ri >/dev/null 2>/dev/null
15+
16+
mkdir -p /etc/chef
17+
18+
cat > /etc/chef/validation.pem <<'EOP'
19+
<%= validation_key %>
20+
EOP
21+
chmod 0600 /etc/chef/validation.pem
22+
23+
<% if encrypted_data_bag_secret -%>
24+
cat > /etc/chef/encrypted_data_bag_secret <<'EOP'
25+
<%= encrypted_data_bag_secret %>
26+
EOP
27+
chmod 0600 /etc/chef/encrypted_data_bag_secret
28+
<% end -%>
29+
30+
<%# Generate Ohai Hints -%>
31+
<% unless @chef_config[:knife][:hints].nil? || @chef_config[:knife][:hints].empty? -%>
32+
mkdir -p /etc/chef/ohai/hints
33+
34+
<% @chef_config[:knife][:hints].each do |name, hash| -%>
35+
cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP'
36+
<%= hash.to_json %>
37+
EOP
38+
<% end -%>
39+
<% end -%>
40+
41+
cat > /etc/chef/client.rb <<'EOP'
42+
<%= config_content %>
43+
EOP
44+
45+
cat > /etc/chef/first-boot.json <<'EOP'
46+
<%= first_boot.to_json %>
47+
EOP
48+
49+
<%= start_chef %>'

0 commit comments

Comments
 (0)