1
------------------------------------------------------------
3
committer: Scott Moser <smoser@ubuntu.com>
5
timestamp: Tue 2011-09-13 11:48:08 -0400
7
[doc] add 'preseed' string to cloud-config for debconf-set-selections
8
------------------------------------------------------------
10
fixes bug(s): https://launchpad.net/bugs/845208
11
committer: Scott Moser <smoser@ubuntu.com>
13
timestamp: Tue 2011-09-13 08:02:37 -0400
15
Chef support fixes, and support for environment and initial attr (LP: #845208)
17
Thanks to Mike Mouulton and Avishai Ish-Shalom.
18
------------------------------------------------------------
19
Use --include-merges or -n0 to see merged revisions.
20
=== modified file 'cloudinit/CloudConfig/cc_chef.py'
21
--- old/cloudinit/CloudConfig/cc_chef.py 2011-09-08 23:10:17 +0000
22
+++ new/cloudinit/CloudConfig/cc_chef.py 2011-09-13 00:38:37 +0000
26
# Author: Avishai Ish-Shalom <avishai@fewbytes.com>
27
+# Author: Mike Moulton <mike@meltmedia.com>
29
# This program is free software: you can redistribute it and/or modify
30
# it under the terms of the GNU General Public License version 3, as
38
import cloudinit.CloudConfig as cc
40
if not cfg.has_key('chef'): return
41
chef_cfg = cfg['chef']
43
- # Install chef packages from selected source
44
- install_type = util.get_cfg_option_str(chef_cfg, "install_type", "packages")
45
- if not os.path.isfile('/usr/bin/chef-client'):
46
- if install_type == "gems":
47
- if chef_cfg.has_key('version'):
48
- chef_version = chef_cfg['version']
51
- install_chef_from_gems(
52
- util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8'),
55
- cc.install_packages(('chef',))
56
+ # ensure the chef directories we use exist
57
+ mkdirs(['/etc/chef', '/var/log/chef', '/var/lib/chef',
58
+ '/var/cache/chef', '/var/backups/chef', '/var/run/chef'])
60
- # set the validation cert
61
- if chef_cfg.has_key('validation_cert'):
62
- with open('/etc/chef/validation.pem', 'w') as validation_cert_fh:
63
- validation_cert_fh.write(chef_cfg['validation_cert'])
64
+ # set the validation key based on the presence of either 'validation_key'
65
+ # or 'validation_cert'. In the case where both exist, 'validation_key'
67
+ if chef_cfg.has_key('validation_key') or chef_cfg.has_key('validation_cert'):
68
+ validation_key = util.get_cfg_option_str(chef_cfg, 'validation_key',
69
+ chef_cfg['validation_cert'])
70
+ with open('/etc/chef/validation.pem', 'w') as validation_key_fh:
71
+ validation_key_fh.write(validation_key)
73
validation_name = chef_cfg.get('validation_name','chef-validator')
74
# create the chef config from template
75
util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
76
{'server_url': chef_cfg['server_url'],
77
+ 'node_name': util.get_cfg_option_str(chef_cfg, 'node_name',
78
+ cloud.datasource.get_instance_id()),
79
+ 'environment': util.get_cfg_option_str(chef_cfg, 'environment',
81
'validation_name': chef_cfg['validation_name']})
84
# set the firstboot json
85
- if chef_cfg.has_key('run_list'):
86
- with open('/etc/chef/firstboot.json', 'w') as firstboot_json_fh:
87
- firstboot_json_fh.write("{\n\"run_list\":\n[\n")
88
- firstboot_json_fh.write(
89
- ",\n".join(["\"%s\"" % runlist_item for runlist_item in chef_cfg['run_list']])
91
- firstboot_json_fh.write("]\n\}")
92
- chef_args.append('-j /etc/chef/firstboot.json')
93
+ with open('/etc/chef/firstboot.json', 'w') as firstboot_json_fh:
95
+ if chef_cfg.has_key('run_list'):
96
+ initial_json['run_list'] = chef_cfg['run_list']
97
+ if chef_cfg.has_key('initial_attributes'):
98
+ initial_attributes = chef_cfg['initial_attributes']
99
+ for k in initial_attributes.keys(): initial_json[k] = initial_attributes[k]
100
+ firstboot_json_fh.write(json.dumps(initial_json))
102
- # and finally, run chef
103
- log.debug("running chef-client %s" % chef_args)
104
- subprocess.check_call(['/usr/bin/chef-client'] + chef_args)
105
+ # If chef is not installed, we install chef based on 'install_type'
106
+ if not os.path.isfile('/usr/bin/chef-client'):
107
+ install_type = util.get_cfg_option_str(chef_cfg, 'install_type', 'packages')
108
+ if install_type == "gems":
109
+ # this will install and run the chef-client from gems
110
+ chef_version = util.get_cfg_option_str(chef_cfg, 'version', None)
111
+ ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8')
112
+ install_chef_from_gems(ruby_version, chef_version)
113
+ # and finally, run chef-client
114
+ log.debug('running chef-client')
115
+ subprocess.check_call(['/usr/bin/chef-client', '-d', '-i', '1800', '-s', '20'])
117
+ # this will install and run the chef-client from packages
118
+ cc.install_packages(('chef',))
120
def install_chef_from_gems(ruby_version, chef_version = None):
121
cc.install_packages(ruby_packages[ruby_version])
122
- gem_bin = get_gem_bin()
123
- if not os.path.exists('/usr/bin/gem'): os.symlink(gem_bin, '/usr/bin/gem')
124
- chef_version_arg = ""
125
- if chef_version: chef_version_arg = "-v %s" % chef_version
126
- subprocess.check_call([gem_bin,'install','chef',chef_version_arg, '--no-ri','--no-rdoc','--no-test','-q'])
127
- os.mkdirs('/etc/chef', '/var/log/chef', '/var/lib/chef', '/var/cache/chef', '/var/backups/chef', '/var/run/chef')
128
- os.symlink('/var/lib/gem/%s/bin/chef-client' % ruby_version, '/usr/bin/chef-client')
129
- # Ohai ruby plugin breaks if there is no ruby or gem binaries at /usr/bin, so
130
- try: os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
132
- try: os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
136
- return '/usr/bin/gem%s' % util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8')
137
+ if not os.path.exists('/usr/bin/gem'):
138
+ os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
139
+ if not os.path.exists('/usr/bin/ruby'):
140
+ os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
142
+ subprocess.check_call(['/usr/bin/gem','install','chef',
143
+ '-v %s' % chef_version, '--no-ri',
144
+ '--no-rdoc','--bindir','/usr/bin','-q'])
146
+ subprocess.check_call(['/usr/bin/gem','install','chef',
147
+ '--no-ri','--no-rdoc','--bindir',
151
+ if not os.path.exists(d):
158
=== modified file 'doc/examples/cloud-config-chef.txt'
159
--- old/doc/examples/cloud-config-chef.txt 2011-04-21 14:57:54 +0000
160
+++ new/doc/examples/cloud-config-chef.txt 2011-09-13 00:38:37 +0000
162
apt_mirror: http://apt.opscode.com/
165
- # If you want to install from rubygems:
167
+ # Valid values are 'gems' and 'packages'
171
server_url: "https://chef.yourorg.com:4000"
174
+ # Defaults to the instance-id if not present
175
+ node_name: "your-node-name"
178
+ # Defaults to '_default' if not present
179
+ environment: "production"
181
# Default validation name is chef-validator
182
validation_name: "yourorg-validator"
184
- -----BEGIN CERTIFICATE-----
185
- MIICCTCCAXKgAwIBAgIBATANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDDAJjYTAe
186
- Fw0xMDAyMTUxNzI5MjFaFw0xNTAyMTQxNzI5MjFaMA0xCzAJBgNVBAMMAmNhMIGf
187
- MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCu7Q40sm47/E1Pf+r8AYb/V/FWGPgc
188
- b014OmNoX7dgCxTDvps/h8Vw555PdAFsW5+QhsGr31IJNI3kSYprFQcYf7A8tNWu
189
- 1MASW2CfaEiOEi9F1R3R4Qlz4ix+iNoHiUDTjazw/tZwEdxaQXQVLwgTGRwVa+aA
190
- qbutJKi93MILLwIDAQABo3kwdzA4BglghkgBhvhCAQ0EKxYpUHVwcGV0IFJ1Ynkv
191
- T3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwDwYDVR0TAQH/BAUwAwEB/zAd
192
- BgNVHQ4EFgQUu4+jHB+GYE5Vxo+ol1OAhevspjAwCwYDVR0PBAQDAgEGMA0GCSqG
193
- SIb3DQEBBQUAA4GBAH/rxlUIjwNb3n7TXJcDJ6MMHUlwjr03BDJXKb34Ulndkpaf
194
- +GAlzPXWa7bO908M9I8RnPfvtKnteLbvgTK+h+zX1XCty+S2EQWk29i2AdoqOTxb
195
- hppiGMp0tT5Havu4aceCXiy2crVcudj3NFciy8X66SoECemW9UYDCb9T5D0d
196
- -----END CERTIFICATE-----
199
+ -----BEGIN RSA PRIVATE KEY-----
200
+ YOUR-ORGS-VALIDATION-KEY-HERE
201
+ -----END RSA PRIVATE KEY-----
203
# A run list for a first boot json
208
+ # Specify a list of initial attributes used by the cookbooks
209
+ initial_attributes:
215
=== modified file 'doc/examples/cloud-config.txt'
216
--- old/doc/examples/cloud-config.txt 2011-08-15 21:39:21 +0000
217
+++ new/doc/examples/cloud-config.txt 2011-09-13 15:48:08 +0000
219
# This can be a single string ('smoser') or a list ([smoser, kirkland])
220
ssh_import_id: [smoser]
222
-# Provide debconf answers
223
+# Provide debconf answers / debian preseed values
225
# See debconf-set-selections man page.
228
=== modified file 'templates/chef_client.rb.tmpl'
229
--- old/templates/chef_client.rb.tmpl 2011-04-21 14:57:54 +0000
230
+++ new/templates/chef_client.rb.tmpl 2011-09-10 22:34:05 +0000
233
-log_location "/var/log/chef/client.log"
234
-ssl_verify_mode :verify_none
236
+log_location "/var/log/chef/client.log"
237
+ssl_verify_mode :verify_none
238
validation_client_name "$validation_name"
239
validation_key "/etc/chef/validation.pem"
240
-client_key "/etc/chef/client.pem"
241
-chef_server_url "$server_url"
242
-file_cache_path "/var/cache/chef"
243
-file_backup_path "/var/backups/chef"
244
-pid_file "/var/run/chef/client.pid"
245
+client_key "/etc/chef/client.pem"
246
+chef_server_url "$server_url"
247
+environment "$environment"
248
+node_name "$node_name"
249
+json_attribs "/etc/chef/firstboot.json"
250
+file_cache_path "/var/cache/chef"
251
+file_backup_path "/var/backups/chef"
252
+pid_file "/var/run/chef/client.pid"
253
Chef::Log::Formatter.show_time = true