add chef [Avishai Ish-Shalom]
This commit is contained in:
commit
c5443146c7
@ -25,6 +25,7 @@
|
|||||||
assuming ~/.ssh/authorized_keys (LP: #731849)
|
assuming ~/.ssh/authorized_keys (LP: #731849)
|
||||||
- fix cloud-init in ubuntu lxc containers (LP: #800824)
|
- fix cloud-init in ubuntu lxc containers (LP: #800824)
|
||||||
- sanitize hosts file for system's hostname to 127.0.1.1 (LP: #802637)
|
- sanitize hosts file for system's hostname to 127.0.1.1 (LP: #802637)
|
||||||
|
- add chef support (cloudinit/CloudConfig/cc_chef.py)
|
||||||
0.6.1:
|
0.6.1:
|
||||||
- fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509)
|
- fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509)
|
||||||
- improve comment strings in rsyslog file tools/21-cloudinit.conf
|
- improve comment strings in rsyslog file tools/21-cloudinit.conf
|
||||||
|
80
cloudinit/CloudConfig/cc_chef.py
Normal file
80
cloudinit/CloudConfig/cc_chef.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# vi: ts=4 expandtab
|
||||||
|
#
|
||||||
|
# Author: Avishai Ish-Shalom <avishai@fewbytes.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License version 3, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
import os
|
||||||
|
import pwd
|
||||||
|
import socket
|
||||||
|
import subprocess
|
||||||
|
import StringIO
|
||||||
|
import ConfigParser
|
||||||
|
import cloudinit.CloudConfig as cc
|
||||||
|
import cloudinit.util as util
|
||||||
|
|
||||||
|
ruby_packages = {'1.8': ('ruby', 'rubygems', 'ruby-dev', 'libopenssl-ruby'),
|
||||||
|
'1.9.1': ('ruby1.9.1', 'ruby1.9.1-dev', 'libruby1.9.1'),
|
||||||
|
'1.9': ('ruby1.9', 'ruby1.9-dev', 'libruby1.9') }
|
||||||
|
|
||||||
|
def handle(name,cfg,cloud,log,args):
|
||||||
|
# If there isn't a chef key in the configuration don't do anything
|
||||||
|
if not cfg.has_key('chef'): return
|
||||||
|
chef_cfg = cfg['chef']
|
||||||
|
|
||||||
|
# Install chef packages from selected source
|
||||||
|
if not os.path.isfile('/usr/bin/chef-client'):
|
||||||
|
if chef_cfg['install_type'] == "gems":
|
||||||
|
if chef_cfg.has_key('version'):
|
||||||
|
chef_version = chef_cfg['version']
|
||||||
|
else:
|
||||||
|
chef_version = None
|
||||||
|
install_chef_from_gems(
|
||||||
|
util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8'),
|
||||||
|
chef_version)
|
||||||
|
else:
|
||||||
|
cc.install_packages(('chef',))
|
||||||
|
|
||||||
|
# set the validation cert
|
||||||
|
if chef_cfg.has_key('validation_cert'):
|
||||||
|
with open('/etc/chef/validation.cert', 'w') as validation_cert_fh:
|
||||||
|
validation_cert_fh.write(chef_cfg['validation_cert'])
|
||||||
|
|
||||||
|
# create the chef config from template
|
||||||
|
util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
|
||||||
|
{'server_url': chef_cfg['server_url'], 'validation_name': chef_cfg['validation_name'] || 'chef-validator'})
|
||||||
|
|
||||||
|
chef_args = ['-d']
|
||||||
|
# set the firstboot json
|
||||||
|
if chef_cfg.has_key('run_list'):
|
||||||
|
with open('/etc/chef/firstboot.json') as firstboot_json_fh:
|
||||||
|
firstboot_json_fh.write("{\n\"run_list\":\n[\n")
|
||||||
|
for runlist_item in chef_cfg['run_list']:
|
||||||
|
firstboot_json_fh.write(runlist_item + "\n")
|
||||||
|
firstboot_json_fh.write("]\n\}")
|
||||||
|
chef_args.append('-j /etc/chef/firstboot.json')
|
||||||
|
|
||||||
|
# and finally, run chef
|
||||||
|
subprocess.check_call(['/usr/bin/chef-client'] + chef_args)
|
||||||
|
|
||||||
|
def install_chef_from_gems(ruby_version, chef_version = None):
|
||||||
|
cc.install_packages(ruby_packages[ruby_version])
|
||||||
|
chef_version_arg = ""
|
||||||
|
if chef_version: chef_version_arg = "-v %s" % chef_version
|
||||||
|
subprocess.check_call([gem_bin,'install','chef',chef_version_arg, '--no-ri','--no-rdoc','--no-test','-q'])
|
||||||
|
os.mkdirs('/etc/chef', '/var/log/chef', '/var/lib/chef', '/var/cache/chef', '/var/backups/chef', '/var/run/chef')
|
||||||
|
os.symlink('/var/lib/gem/%s/bin/chef-client' % ruby_version, '/usr/bin/chef-client')
|
||||||
|
# Ohai ruby plugin breaks if there is no ruby or gem binaries at /usr/bin, so
|
||||||
|
try: os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
|
||||||
|
except: pass
|
||||||
|
try: os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
|
||||||
|
except: pass
|
38
doc/examples/cloud-config-chef.txt
Normal file
38
doc/examples/cloud-config-chef.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#cloud-config
|
||||||
|
#
|
||||||
|
# This is an example file to automatically setup and run puppetd
|
||||||
|
# when the instance boots for the first time.
|
||||||
|
# Make sure that this file is valid yaml before starting instances.
|
||||||
|
# It should be passed as user-data when starting the instance.
|
||||||
|
|
||||||
|
# The default is to install from packages. If you want the latest packages from Opscode, be sure to add their repo:
|
||||||
|
apt_mirror: http://apt.opscode.com/
|
||||||
|
|
||||||
|
chef:
|
||||||
|
# If you want to install from rubygems:
|
||||||
|
install_type: "gems"
|
||||||
|
|
||||||
|
# Chef settings
|
||||||
|
server_url: "https://chef.yourorg.com:4000"
|
||||||
|
|
||||||
|
# Default validation name is chef-validator
|
||||||
|
validation_name: "yourorg-validator"
|
||||||
|
validation_cert: |
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIICCTCCAXKgAwIBAgIBATANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDDAJjYTAe
|
||||||
|
Fw0xMDAyMTUxNzI5MjFaFw0xNTAyMTQxNzI5MjFaMA0xCzAJBgNVBAMMAmNhMIGf
|
||||||
|
MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCu7Q40sm47/E1Pf+r8AYb/V/FWGPgc
|
||||||
|
b014OmNoX7dgCxTDvps/h8Vw555PdAFsW5+QhsGr31IJNI3kSYprFQcYf7A8tNWu
|
||||||
|
1MASW2CfaEiOEi9F1R3R4Qlz4ix+iNoHiUDTjazw/tZwEdxaQXQVLwgTGRwVa+aA
|
||||||
|
qbutJKi93MILLwIDAQABo3kwdzA4BglghkgBhvhCAQ0EKxYpUHVwcGV0IFJ1Ynkv
|
||||||
|
T3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwDwYDVR0TAQH/BAUwAwEB/zAd
|
||||||
|
BgNVHQ4EFgQUu4+jHB+GYE5Vxo+ol1OAhevspjAwCwYDVR0PBAQDAgEGMA0GCSqG
|
||||||
|
SIb3DQEBBQUAA4GBAH/rxlUIjwNb3n7TXJcDJ6MMHUlwjr03BDJXKb34Ulndkpaf
|
||||||
|
+GAlzPXWa7bO908M9I8RnPfvtKnteLbvgTK+h+zX1XCty+S2EQWk29i2AdoqOTxb
|
||||||
|
hppiGMp0tT5Havu4aceCXiy2crVcudj3NFciy8X66SoECemW9UYDCb9T5D0d
|
||||||
|
-----END CERTIFICATE-----
|
||||||
|
|
||||||
|
# A run list for a first boot json
|
||||||
|
run_list:
|
||||||
|
- "recipe[apache2]"
|
||||||
|
- "role[db]"
|
12
templates/chef_client.rb.tmpl
Normal file
12
templates/chef_client.rb.tmpl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
log_level :info
|
||||||
|
log_location "/var/log/chef/client.log"
|
||||||
|
ssl_verify_mode :verify_none
|
||||||
|
validation_client_name "$validation_name"
|
||||||
|
validation_key "/etc/chef/validation.pem"
|
||||||
|
client_key "/etc/chef/client.pem"
|
||||||
|
chef_server_url "$server_url"
|
||||||
|
file_cache_path "/var/cache/chef"
|
||||||
|
file_backup_path "/var/backups/chef"
|
||||||
|
pid_file "/var/run/chef/client.pid"
|
||||||
|
Chef::Log::Formatter.show_time = true
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user