diff --git a/.kitchen.cloud.yml b/.kitchen.cloud.yml index 88782a6..f1d1713 100644 --- a/.kitchen.cloud.yml +++ b/.kitchen.cloud.yml @@ -20,20 +20,20 @@ provisioner: require_chef_omnibus: latest platforms: -- name: centos-5.8 +- name: centos-5.11 driver_plugin: digital_ocean driver_config: size: 2gb - image: centos-5-8-x64 + image: centos-5-11-x64 region: <%= ENV['DIGITAL_OCEAN_REGION'] %> ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> ssh_key: <%= ENV['DIGITAL_OCEAN_SSH_KEY_PATH'] %> -- name: centos-6.5 +- name: centos-6.6 driver_plugin: digital_ocean driver_config: size: 2gb - image: centos-6-5-x64 + image: centos-6-6-x64 region: <%= ENV['DIGITAL_OCEAN_REGION'] %> ssh_key_ids: <%= ENV['DIGITAL_OCEAN_SSH_KEY_IDS'] %> ssh_key: <%= ENV['DIGITAL_OCEAN_SSH_KEY_PATH'] %> @@ -84,3 +84,10 @@ suites: attributes: machine_fqdn: chef.computers.biz fqdn_as_hostname: true +- name: no-fqdn + run_list: + - recipe[test] + - recipe[chef-server::default] + attributes: + chef-server: + api_fqdn: "" diff --git a/.kitchen.yml b/.kitchen.yml index 34a2f27..e0428d8 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -1,22 +1,36 @@ driver: name: vagrant + customize: + memory: 1024 + cpus: 2 provisioner: name: chef_zero - require_chef_omnibus: latest platforms: - name: ubuntu-10.04 -- name: ubuntu-10.10 - name: ubuntu-12.04 -- name: ubuntu-12.10 -- name: ubuntu-13.04 -- name: ubuntu-13.10 -- name: centos-6.5 +- name: ubuntu-14.04 +- name: centos-6.6 - name: centos-5.10 +- name: centos-5.11 suites: - name: default run_list: + - recipe[test] - recipe[chef-server] - attributes: {} + attributes: + chef-server: + api_fqdn: 'chef-server-tk.example.com' + +- name: no-fqdn + run_list: + - recipe[test] + - recipe[chef-server] + driver: + network: + - ['private_network', {ip: '192.168.243.2'}] + attributes: + chef-server: + api_fqdn: '' diff --git a/Berksfile b/Berksfile index 7345a4f..dcb7dbc 100644 --- a/Berksfile +++ b/Berksfile @@ -2,8 +2,6 @@ source 'https://supermarket.chef.io' metadata -group :dev do - cookbook 'git' - cookbook 'apt' - cookbook 'fqdn' +group :integration do + cookbook 'test', :path => './test/fixtures/cookbooks/test' end diff --git a/README.md b/README.md index 57c9ab1..8a4e0fa 100644 --- a/README.md +++ b/README.md @@ -1,251 +1,97 @@ -Chef Server -=========== +# chef-server -This cookbook configures a system to be a Chef Server. It will install -the appropriate platform-specific chef-server Omnibus package and -perform the initial configuration of Chef Server. +This cookbook configures a system to be a *standalone* Chef Server. It will install the appropriate platform-specific chef-server Omnibus package from Package Cloud and perform the initial configuration. -## Omnibus-based Chef-Server Overview +It is not in the scope of this cookbook to handle more complex Chef Server topologies like 'tiered' or 'ha'. Nor is it in the scope of this cookbook to install and configure premium features or other add-ons. For clustered Chef Server deployments, see [chef-server-cluster](https://github.com/opscode-cookbooks/chef-server-cluster). For primitives for installing `chef-server-core` or other Chef Server add-ons, see [chef-server-ingredient](https://supermarket.chef.io/cookbooks/chef-server-ingredient). -To understand how this cookbook works it is useful to understand how a -Chef Server instance installed via Omnibus packages behaves. +It is also not in the scope of this cookbook to handle older versions of Chef Server, such as 11 or 10. For Chef Server 11, see version 2.1.x of this cookbook on Supermarket, or the `chef11` branch of this repository. -### Know an Omnibus +# Requirements -Omnibus allows you to build self-contained full-stack software -packages. We use Omnibus to to distribute the Chef Server bundled with -its dependencies such as Erlang, Ruby, PostgreSQL, RabbitMQ, and -Nginx. The result is a single package that can be installed on the -target system and configured. +This cookbook is tested with Chef (client) 12. It may work with or without modification on earlier versions of Chef, but Chef 12 is recommended. -Omnibus packages separate the installation step from the configuration -step. After an Omnibus package is installed, a configuration step must -be run before the installed system can be used. In particular, this -approach makes handling upgrades easier. +## Cookbooks -### Configuring Chef Server - -Chef Server is configured through the -`/etc/chef-server/chef-server.rb` file. Standalone single-server -configurations do not require custom configuration and can use the -default values for everything. - -You can read all about Chef Server's -[configuration options](http://docs.chef.io/config_rb_chef_server.html). - -### Applying configuration changes - -The `chef-server-ctl reconfigure` command reads the -`/etc/chef-server/chef-server.rb` file and applies the specified -configuration to the system. Any time you make a change to your -configuration, you need to run `chef-server-ctl reconfigure` to apply -it. - -### chef-server-ctl - -Omnibus-based Chef Server installs have a command line utility, -`chef-server-ctl`, which is used to operate the Chef Server. For -example, you can use `chef-server-ctl` to start and stop individual -services, reconfigure the entire server, and tail server log files. - -`chef-server-ctl` commands are documented below: - - $ chef-server-ctl COMMAND - -command | Action ------------|--------- -help | Print a list of all the available chef-server-ctl commands. -status | Shows the status of the Chef Server services. -start | Start all the enabled Chef Server services. -stop | Stop all the enabled Chef Server services. -restart | Restart all the enabled chef server services. -tail | Follow the Chef Server logs for all services. -test | Executes, chef-pedant, the integration test suite against the Chef Server installation. By default only a subset of tests are run, add the `--all` flag to run the full test suite. - -The status, start, stop, restart, and tail commands can optionally be -applied to a single service by adding the service name to the end of -the command line. For example, to get the status of the erchef -component of Chef Server, you can run: - - chef-server-ctl status erchef - - -REQUIREMENTS -============ - -Chef 10 +* chef-server-ingredient cookbook -Platform --------- +## Platform -Chef Server Omnibus packages are available for the following platforms: +This cookbook is tested on the following platforms using the [Test Kitchen](http://kitchen.ci) `.kitchen.yml` in the repository. -* CentOS 5 64-bit -* CentOS 6 64-bit +* RHEL/CentOS 5 64-bit +* RHEL/CentOS 6 64-bit * Ubuntu 10.04, 10.10 64-bit * Ubuntu 11.04, 11.10 64-bit * Ubuntu 12.04, 12.10 64-bit -ATTRIBUTES -========== +Unlisted platforms in the same family, of similar or equivalent versions may work with or without modification to this cookbook. For a list of supported platforms for Chef Server, see the [Chef documentation](https://docs.chef.io/supported_platforms.html#chef-server-title). + +# Attributes The attributes used by this cookbook are under the `chef-server` name space. Attribute | Description |Type | Default -----------------|-------------|-----|-------- -api_fqdn | Fully qualified domain name that you want to use for accessing the Web UI and API. | String | node['fqdn'] +api_fqdn | Fully qualified domain name that you want to use for accessing the Web UI and API. If set to `nil` or empty string (`""`), the IP address will be used as hostname. | String | node['fqdn'] configuration | Configuration values to pass down to the underlying server config file (i.e. `/etc/chef-server/chef-server.rb`). | Hash | Hash.new -package_file | Location of the Omnibus package to install. This should not be set if you wish to pull the packages from the Omnitruck S3 bucket. | String | nil -package_checksum | SHA256 checksum of package referenced by `package_file`. | String | nil -version | Chef Server version to install. This value is ignored if `package_file` is set. | String | :latest -prereleases | Indicates prerelease builds should be downloaded from Omnitruck. Prerelease builds come out in the weeks leading up to a major release. Prereleases offer an early preview of the next upcoming stable release and are intended for testers and advanced users. This value is ignored if `package_file` is set. | Boolean | false -nightlies | Indicates nightly builds should be downloaded from Omnitruck. Nightly builds of chef-server usually come out every night, but may be less frequent if there are no changes to the code, or the CI infrastructure is unable to create a build that day. The nightly builds are intended for testing only. This value is ignored if `package_file` is set. | Boolean | false +version | Chef Server version to install. If `nil`, the latest version is installed | String | nil + +Previous versions of this cookbook had several other attributes used to control the version of the Chef Server package to install. This is deprecated. -RECIPES -======== +# Recipes -This section describes the recipes in the cookbook and how to use them -in your environment. +This section describes the recipes in the cookbook and how to use them in your environment. -default -------- +## default This recipe: -* Installs the appropriate platform-specific chef-server Omnibus package. +* Installs the appropriate platform-specific chef-server Omnibus package from our Package Cloud [repository](https://packagecloud.io/chef/stable) * Creates the initial `/etc/chef-server/chef-server.rb` file. * Performs initial system configuration via `chef-server-ctl reconfigure`. +* Updates the `/etc/hosts` file with the `api_fqdn` if that FQDN cannot be resolved. -Omnibus package selection is done based on the following logic: - -1. If a value has been provided, the chef-server Omnibus package is - fetched from `node['chef-server']['package_file']` -2. If `node['chef-server']['package_file']` is unset (ie nil or empty - string), the candidate package is retrieved from the Omnitruck REST - API based on `node['chef-server']['version']` AND the node - platform, platform_version and architecture. By default the latest package - is installed. If you would like to download pre-release or nightly builds - set appropriate attribute to `true`. - -dev ---- - -This recipe converts a Chef Server installation into development mode -for easy hacking on the underlying server components. This recipe should -not be run on a production server. - -This recipe will place checkouts for all of Chef Server's main -software components at `/opt/chef-server-dev/code`. These component -checkouts will also be symlinked into the underlying Chef Server -installation. Changes made to component code will be reflected in the -running Chef Server instance (most often only after a restart of the -given service). - -INSTALL METHODS -=============== +# Install Methods ## Bootstrap Chef (server) with Chef (solo) -The easiest way to get a Chef Server up and running is to install -chef-solo (via the chef-client Omnibus packages) and bootstrap the -system using this cookbook: +The easiest way to get a Chef Server up and running is to install chef-solo (via the chef-client Omnibus packages) and bootstrap the system using this cookbook: # install chef-solo curl -L https://www.chef.io/chef/install.sh | sudo bash # create required bootstrap dirs/files - sudo mkdir -p /var/chef/cache /var/chef/cookbooks/chef-server + sudo mkdir -p /var/chef/cache /var/chef/cookbooks # pull down this chef-server cookbook - sudo wget -qO- https://github.com/chef-cookbooks/chef-server/archive/master.tar.gz | tar xvzC /var/chef/cookbooks/chef-server --strip-components=1 + wget -qO- https://supermarket.chef.io/cookbooks/chef-server/download | sudo tar xvzC /var/chef/cookbooks + # pull down dependency cookbooks + wget -qO- https://supermarket.chef.io/cookbooks/chef-server-ingredient/download | sudo tar xvzC /var/chef/cookbooks + wget -qO- https://supermarket.chef.io/cookbooks/packagecloud/download | sudo tar xvzC /var/chef/cookbooks # GO GO GO!!! sudo chef-solo -o 'recipe[chef-server::default]' -If you need more control over the final configuration of your Chef -Server instance you can create a JSON attributes file and set -underlying configuration via the -`node['chef-server']['configuration']` attribute. For example, you can -disable the webui with the following configuration: - - echo '{ - "chef-server": { - "configuration": { - "chef_server_webui": { - "enable": false - } - } - }, - "run_list": [ "recipe[chef-server::default]" ] - }' > /tmp/no-webui.json - -You would then pass this file to the initial chef-solo command: - - chef-solo -j /tmp/no-webui.json - -## Demo Chef Server with Vagrant and Berkshelf - -We <3 the wonderful open-source tools -[Berkshelf](http://berkshelf.com/) and -[Vagrant](http://vagrantup.com/). You can take Chef Server for a spin -using the Berksfile and Vagrantfile that ship alongside this cookbook. -The only requirements for standing up a virtualized Chef Server are: - -* VirtualBox - native packages exist for most platforms and can be downloaded -from the [VirtualBox downloads page](https://www.virtualbox.org/wiki/Downloads). -* Vagrant 1.3.2+ - native packages exist for most platforms and can be downloaded -from the [Vagrant downloads page](http://downloads.vagrantup.com/). - -The [vagrant-berkshelf](https://github.com/RiotGames/vagrant-berkshelf) and -[vagrant-omnibus](https://github.com/schisamo/vagrant-omnibus) Vagrant plugins -are also required and can be installed easily with the following commands: - -```shell -$ vagrant plugin install vagrant-berkshelf -$ vagrant plugin install vagrant-omnibus -``` - -Once the pre-requisites are installed you can start the virtualized environment -with the following command: - -```shell -$ vagrant up -``` - -Although things have only been tested with Vagrant's `virtualbox` provider -everything should work with other providers like `vmware_fusion` or `ec2`. +Be sure to download and untar the `chef-server-ingredient` and `packagecloud` cookbooks. They're dependencies of this cookbook. -You can easily SSH into the running VM using the `vagrant ssh` command. -The VM can easily be stopped and deleted with the `vagrant destroy` -command. Please see the official -[Vagrant documentation](http://vagrantup.com/v1/docs/commands.html) for a more -in depth explanation of available commands. +If you need more control over the final configuration of your Chef Server instance you can create a JSON attributes file and set underlying configuration via the `node['chef-server']['configuration']` attribute. See the [attributes/default.rb](attributes/default.rb) -The running Chef-Server components are accessible from the host machine -using the following URLs: +Then pass this file to the initial chef-solo command: -* Web UI: https://33.33.33.50/ (Note: Attempts to hit via straight http will be -redirected to the Vagrant guest's internal hostname) -* Version Manifest: https://33.33.33.50/version -* Chef Server API (routing requires `X-OPS-USERID` HTTP header being properly -set): https://33.33.33.50/ + chef-solo -j /tmp/dna.json -*Note: It can be helpful to use the host workstation's /etc/hosts file to map -33.33.33.50 to chef-server-berkshelf.* +### Configuring Chef Server -## Contribute to and Hack on Chef Server (including Erchef) +You can read all about Chef Server's configuration options on the [Chef Documentation site](http://docs.chef.io/server/config_rb_server.html). -This cookbook ships with a recipe named `dev` that will take any Chef -Server instance and flip it into development mode. If you want to use -the Vagrant-based environment referenced above, edit the `chef.run_list` -value in the `Vagrantfile` to include an additional -`recipe[chef-server::dev]` run list item. +### Applying configuration changes +The `chef-server-ctl` command is the administrative interface to the Chef Server. It has its own [documentation](https://docs.chef.io/ctl_chef_server.html). Various administrative functions provided by `chef-server-ctl` are not in the scope of this cookbook. Special/customized needs should be managed in your own cookbook. -LICENSE AND AUTHORS -=================== +# License and Authors * Author: Seth Chisamore +* Author: Joshua Timberman +* Copyright 2012-2015, Chef Software, Inc -Copyright 2012, Chef Software, Inc - +```text Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -256,3 +102,4 @@ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and +``` diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index ec3ba60..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,74 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure('2') do |config| - -# Plugin-specific configurations - # Detects vagrant-cachier plugin - if Vagrant.has_plugin?('vagrant-cachier') - puts 'INFO: Vagrant-cachier plugin detected. Optimizing caches.' - config.cache.auto_detect = true - config.cache.enable :chef - config.cache.enable :apt - else - puts 'WARN: Vagrant-cachier plugin not detected. Continuing unoptimized.' - end - - # Detects vagrant-omnibus plugin - if Vagrant.has_plugin?('vagrant-omnibus') - puts 'INFO: Vagrant-omnibus plugin detected.' - config.omnibus.chef_version = :latest - else - puts "FATAL: Vagrant-omnibus plugin not detected. Please install the plugin with\n 'vagrant plugin install vagrant-omnibus' from any other directory\n before continuing." - exit - end - - # Detects vagrant-berkshelf plugin - if Vagrant.has_plugin?('berkshelf') - # The path to the Berksfile to use with Vagrant Berkshelf - puts 'INFO: Vagrant-berkshelf plugin detected.' - config.berkshelf.berksfile_path = './Berksfile' - else - puts "FATAL: Vagrant-berkshelf plugin not detected. Please install the plugin with\n 'vagrant plugin install vagrant-berkshelf' from any other directory\n before continuing." - exit - end - - config.vm.hostname = 'chef-server' - - config.vm.box = 'chef-ubuntu-12.04' - config.vm.box_url = 'http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-12.04_chef-provisionerless.box' - - # Alternate images that are also suitable for use with this recipe - # config.vm.box = "canonical-ubuntu-12.04" - # config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" - # config.vm.box = "chef-centos-6.5" - # config.vm.box_url = "https://chef-vm-bento.s3.amazonaws.com/vagrant/virtualbox/chef_centos-6.5_provisionerless.box" - - config.vm.network :private_network, :ip => '33.33.33.50' - - config.vm.provider :virtualbox do |vb| - # Give enough horsepower to build without taking all day. - vb.customize [ - 'modifyvm', :id, - '--memory', '1024', - '--cpus', '2', - ] - end - - # Enable SSH agent forwarding for git clones - config.ssh.forward_agent = true - - - config.vm.provision :chef_solo do |chef| - # chef.provisioning_path = guest_cache_path - chef.json = { - 'chef-server' => { - 'version' => :latest - } - } - - chef.run_list = [ - 'recipe[chef-server::default]' - ] - end -end diff --git a/attributes/default.rb b/attributes/default.rb index 9490063..435d3ee 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -2,7 +2,7 @@ # Cookbook Name:: chef-server # Attributes:: default # -# Copyright:: Copyright (c) 2012 Chef Software, Inc. +# Copyright:: Copyright (c) 2012-2015 Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +# +# +default['chef-server']['version'] = nil -default['chef-server']['version'] = :latest -default['chef-server']['prereleases'] = false -default['chef-server']['nightlies'] = false -default['chef-server']['package_file'] = nil -default['chef-server']['package_checksum'] = nil -default['chef-server']['package_options'] = nil +# The Chef Server must have an API FQDN set. +# Ref. http://docs.chef.io/install_server_pre.html#hostnames default['chef-server']['api_fqdn'] = node['fqdn'] # # Chef Server Tunables # # For a complete list see: -# https://github.com/chef/omnibus-chef-server/blob/master/files/chef-server-cookbooks/chef-server/attributes/default.rb +# http://docs.chef.io/server/config_rb_server.html # # Example: # @@ -38,7 +37,7 @@ # # In a role: # -# override_attributes( +# default_attributes( # 'chef-server' => { # 'configuration' => { # 'nginx' => { diff --git a/libraries/dev_helper.rb b/libraries/dev_helper.rb deleted file mode 100644 index 51bf761..0000000 --- a/libraries/dev_helper.rb +++ /dev/null @@ -1,100 +0,0 @@ -# -# Copyright:: Copyright (c) 2012 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require 'mixlib/shellout' - -# DevHelper -module DevHelper - def self.omnibus_path - '/opt/chef-server/bin:/opt/chef-server/embedded/bin:/opt/chef-server/embedded/jre/bin' - end - - def self.code_root - '/opt/chef-server-dev/code' - end - - def self.backup_root - '/opt/chef-server-dev/backup' - end - - def self.omnibus_service_root - '/opt/chef-server/embedded/service' - end - - # Project - class Project - attr_accessor :name, :options - attr_accessor :checkout_path, :omnibus_path - attr_accessor :build_command, :preserved_paths - - def initialize(name, options) - @name = name - @options = options - @checkout_path = File.join(DevHelper.code_root, name) - @omnibus_path = options[:omnibus_path] || File.join(DevHelper.omnibus_service_root, name) - @build_command = options[:build_command] || nil - @preserved_paths = options[:preserved_paths] || [] - end - - def build_and_load - shell_out("chef-server-ctl stop #{options[:service_name]}") if options.key?(:service_name) - build - link - configure - shell_out("chef-server-ctl start #{options[:service_name]}") if options.key?(:service_name) - end - - private - - def build - shell_out(options[:build_command], :cwd => checkout_path) if build_command - end - - def link - if File.exists?(omnibus_path) && !File.symlink?(omnibus_path) - if options.key?(:release_path) - release_path = File.join(checkout_path, options[:release_path]) - else - release_path = checkout_path - end - FileUtils.mv(omnibus_path, DevHelper.backup_root) - FileUtils.ln_s(release_path, omnibus_path) - end - end - - def configure - preserved_paths.each do |path| - backup_path = File.join(DevHelper.backup_root, name, path) - dest_path = File.join(omnibus_path, path) - if File.exists?(backup_path) - FileUtils.mkdir_p(File.dirname(dest_path)) - FileUtils.cp_r(backup_path, dest_path, :remove_destination => true, :preserve => true) - end - end - end - - def shell_out(command, options = {}) - default_opts = { - :environment => { 'PATH' => "#{DevHelper.omnibus_path}:#{ENV['PATH']}" }, - :live_stream => STDOUT - } - c = Mixlib::ShellOut.new(command, default_opts.merge(options)) - c.run_command - c.error! - end - end -end diff --git a/libraries/omnitruck_client.rb b/libraries/omnitruck_client.rb deleted file mode 100644 index 7ba61d8..0000000 --- a/libraries/omnitruck_client.rb +++ /dev/null @@ -1,69 +0,0 @@ -# -# Copyright:: Copyright (c) 2012 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require 'uri' - -# OmnitruckClient -class OmnitruckClient - attr_reader :platform, :platform_version, :machine_architecture - - def initialize(node) - @platform = node['platform_family'] == 'rhel' ? 'el' : node['platform'] - if node['platform_family'] == 'rhel' - if node['platform'] == 'amazon' - @platform_version = '6' - else - @platform_version = node['platform_version'].to_i - end - else - @platform_version = node['platform_version'] - end - @machine_architecture = node['kernel']['machine'] - end - - def package_for_version(version, prerelease = false, nightly = false) - url = 'http://www.chef.io/chef/download-server' - url << "?p=#{platform}" - url << "&pv=#{platform_version}" - url << "&m=#{machine_architecture}" - url << "&v=#{version}" if version - url << "&prerelease=#{prerelease}" - url << "&nightlies=#{nightly}" - Chef::Log.info("Omnitruck download-server request: #{url}") - target = redirect_target(url) - Chef::Log.info("Downloading chef-server package from: #{target}") if target - target - end - - private - - def redirect_target(url) - url = URI.parse(url) - http = Net::HTTP.new(url.host, url.port) - if url.scheme == 'https' - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_NONE - end - response = http.get(url.request_uri, {}) - case response - when Net::HTTPRedirection - response['location'] - else - nil - end - end -end diff --git a/metadata.rb b/metadata.rb index e891f25..ab8030f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -2,12 +2,10 @@ maintainer 'Chef Software, Inc.' maintainer_email 'cookbooks@chef.io' license 'Apache 2.0' -description 'Installs and configures Chef Server' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +description 'Installs and configures Chef Server 12' version '2.1.7' supports 'centos' -supports 'amazon' supports 'ubuntu' -# depends 'git' +depends 'chef-server-ingredient' diff --git a/recipes/default.rb b/recipes/default.rb index 952d676..b6eaad2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright (c) 2012 Chef Software, Inc. +# Copyright:: Copyright (c) 2012-2015 Chef Software, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,90 +12,25 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +# require 'resolv' -require 'chef/util/file_edit' - -# Acquire the chef-server Omnibus package -if node['chef-server']['package_file'].nil? || node['chef-server']['package_file'].empty? - omnibus_package = OmnitruckClient.new(node).package_for_version( - node['chef-server']['version'], - node['chef-server']['prereleases'], - node['chef-server']['nightlies'] - ) - unless omnibus_package - err_msg = 'Could not locate chef-server' - err_msg << ' pre-release' if node['chef-server']['prereleases'] - err_msg << ' nightly' if node['chef-server']['nightlies'] - err_msg << " package matching version '#{node['chef-server']['version']}' for node." - fail err_msg - end -else - omnibus_package = node['chef-server']['package_file'] -end - -package_name = ::File.basename(omnibus_package) -package_local_path = "#{Chef::Config[:file_cache_path]}/#{package_name}" - -# Ensure :file_cache_path exists -directory Chef::Config[:file_cache_path] do - owner 'root' - group 'root' - recursive true - action :create -end - -# omnibus_package is remote (ie a URI) let's download it -if ::URI.parse(omnibus_package).absolute? - remote_file package_local_path do - source omnibus_package - if node['chef-server']['package_checksum'] - checksum node['chef-server']['package_checksum'] - action :create - else - action :create_if_missing - end - end - # else we assume it's on the local machine -else - package_local_path = omnibus_package -end -# install the platform package -package package_name do # ignore ~FC009 known bug in food critic causes this to trigger see Foodcritic Issue #137 - source package_local_path - provider case node['platform_family'] - when 'debian' then Chef::Provider::Package::Dpkg - when 'rhel' then Chef::Provider::Package::Rpm - else - fail RuntimeError("I don't know how to install chef-server packages for platform family '#{node["platform_family"]}'!") - end - options node['chef-server']['package_options'] - action :install - notifies :run, 'execute[reconfigure-chef-server]' +chef_server_ingredient 'chef-server-core' do + version node['chef-server']['version'] + notifies :reconfigure, 'chef_server_ingredient[chef-server-core]' end -# create the chef-server etc directory -directory '/etc/chef-server' do - owner 'root' - group 'root' +directory '/etc/opscode' do recursive true - action :create end # create the initial chef-server config file -template '/etc/chef-server/chef-server.rb' do +template '/etc/opscode/chef-server.rb' do source 'chef-server.rb.erb' owner 'root' group 'root' action :create - notifies :run, 'execute[reconfigure-chef-server]', :immediately -end - -# reconfigure the installation -execute 'reconfigure-chef-server' do - command 'chef-server-ctl reconfigure' - action :nothing + notifies :reconfigure, 'chef_server_ingredient[chef-server-core]' end ruby_block 'ensure node can resolve API FQDN' do @@ -105,5 +40,6 @@ "127.0.0.1 #{node['chef-server']['api_fqdn']}") fe.write_file end + not_if { node['chef-server']['api_fqdn'].nil? || node['chef-server']['api_fqdn'].empty? } not_if { Resolv.getaddress(node['chef-server']['api_fqdn']) rescue false } # host resolves end diff --git a/recipes/dev.rb b/recipes/dev.rb deleted file mode 100644 index adb14ce..0000000 --- a/recipes/dev.rb +++ /dev/null @@ -1,86 +0,0 @@ -# -# Copyright:: Copyright (c) 2012 Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -include_recipe 'git' - -repos = { - 'chef_authn' => {}, - 'chef_certgen' => {}, - 'chef_db' => {}, - 'chef_index' => {}, - 'chef_objects' => {}, - 'chef_wm' => {}, - 'erchef' => { - :service_name => 'erchef', - :preserved_paths => [ - 'etc/app.config', - 'log', - 'bin/erchef' - ], - :build_command => 'rebar get-deps && make clean relclean devrel', - :release_path => 'rel/erchef' - }, - 'chef-server-webui' => { - :service_name => 'chef-server-webui', - :preserved_paths => [ - 'config/environments/chefserver.rb', - 'tmp', - 'config/initializers/secret_token.rb', - 'config/initializers/session_store.rb', - 'config.ru' - ], - :build_command => 'bundle install --deployment --without development' - }, - 'omnibus-chef' => { - :omnibus_path => '/opt/chef-server/embedded/cookbooks', - :release_path => 'files/chef-server-cookbooks' - }, - 'chef-pedant' => { - :build_command => 'bundle install' - } -} - -[DevHelper.code_root, DevHelper.backup_root].each do |dir| - directory dir do - owner 'root' - group 'root' - recursive true - action :create - end -end - -repos.each do |project, options| - - github_name = options.key?(:github_name) ? options[:github_name] : project - - git ::File.join(DevHelper.code_root, project) do - repository "https://github.com/chef/#{github_name}" - reference 'master' - action :checkout - end - - ruby_block "build and load #{project}" do - block do - p = DevHelper::Project.new(project, options) - p.build_and_load - end - end -end - -# Ensure the /opt/chef-server bin/ dirs is first in our PATH -file '/etc/profile.d/omnibus-embedded.sh' do - content "export PATH=\"#{DevHelper.omnibus_path}:$PATH\"" - action :create -end diff --git a/templates/default/chef-server.rb.erb b/templates/default/chef-server.rb.erb index 75ac555..5b3fb99 100644 --- a/templates/default/chef-server.rb.erb +++ b/templates/default/chef-server.rb.erb @@ -2,7 +2,9 @@ topology "standalone" +<% unless node['chef-server']['api_fqdn'].nil? || node['chef-server']['api_fqdn'].empty? -%> api_fqdn "<%= node['chef-server']['api_fqdn'] %>" +<% end -%> <% node['chef-server']['configuration'].each_pair do |component, tunables| -%> <% case tunables -%> diff --git a/test/fixtures/cookbooks/test/README.md b/test/fixtures/cookbooks/test/README.md new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/cookbooks/test/metadata.rb b/test/fixtures/cookbooks/test/metadata.rb new file mode 100644 index 0000000..b3cd45b --- /dev/null +++ b/test/fixtures/cookbooks/test/metadata.rb @@ -0,0 +1,2 @@ +name 'test' +version '0.0.1' diff --git a/test/fixtures/cookbooks/test/recipes/default.rb b/test/fixtures/cookbooks/test/recipes/default.rb new file mode 100644 index 0000000..071c8ba --- /dev/null +++ b/test/fixtures/cookbooks/test/recipes/default.rb @@ -0,0 +1,15 @@ +# This test recipe is used within test kitchen to perform additional +# setup, or to configure custom resources in the main cookbook. + +# For example, update the apt cache on Debian systems, which avoids +# requiring the `apt` cookbook. This doesn't work, of course, if the +# apt cache must be updated before the main cookbook's default recipe +# is run. +execute 'apt-get update' if platform_family?('debian') + +# workaround for https://github.com/chef/bento/issues/325 +remote_file '/etc/pki/tls/certs/ca-bundle.crt' do + source 'http://opscode-omnibus-cache.s3.amazonaws.com/cacerts-2014.07.15-fd48275847fa10a8007008379ee902f1' + checksum 'a9cce49cec92304d29d05794c9b576899d8a285659b3f987dd7ed784ab3e0621' + sensitive true +end if platform_family?('rhel') diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..f490981 --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,21 @@ +require_relative './spec_helper' +require 'resolv' + +describe 'chef-server' do + describe package('chef-server-core') do + it { should be_installed } + end + + describe file('/etc/opscode/chef-server.rb') do + its(:content) { should match(/^topology "standalone"$/) } + its(:content) { should match(/^api_fqdn ".+"$/) } + end + + describe file('/etc/hosts') do + its(:content) { should match(/127.0.0.1 chef-server-tk.example.com/) } + end + + describe command('chef-server-ctl test') do + its(:exit_status) { should eq 0 } + end +end diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb new file mode 100644 index 0000000..677ae95 --- /dev/null +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'serverspec' + +set :backend, :exec + diff --git a/test/integration/no-fqdn/serverspec/default_spec.rb b/test/integration/no-fqdn/serverspec/default_spec.rb new file mode 100644 index 0000000..3738e47 --- /dev/null +++ b/test/integration/no-fqdn/serverspec/default_spec.rb @@ -0,0 +1,12 @@ +require_relative './spec_helper' +require 'resolv' + +describe 'chef-server-no-fqdn' do + describe file('/etc/opscode/chef-server.rb') do + its(:content) { should_not match(/^api_fqdn.*$/)} + end + + describe command('chef-server-ctl test') do + its(:exit_status) { should eq 0 } + end +end