Skip to content

Instantly share code, notes, and snippets.

@xeon22
Created January 13, 2015 18:27
Show Gist options
  • Save xeon22/7fbefed18420e369dc7e to your computer and use it in GitHub Desktop.
Save xeon22/7fbefed18420e369dc7e to your computer and use it in GitHub Desktop.
chef-provisioning-recipe
#
# Cookbook Name:: pcc_provisioning
# Recipe:: default
#
# Copyright (C) 2014 Wescom Solutions Inc.
#
# All rights reserved - Do Not Redistribute
#
%w[
chef-provisioning
chef-provisioning-aws
chef-provisioning-fog
].each do |rubygem|
chef_gem rubygem
end
require 'deep_merge'
require 'chef/provisioning'
with_driver('fog', use_private_ip_for_ssh: true)
node.set['chef_provisioning']['location']['install_msi_url'] = 'https://www.opscode.com/chef/install.msi'
node.set['chef_provisioning']['location']['use_private_ip_for_ssh'] = true
with_chef_server "https://chef-server",
:client_name => 'username',
:signing_key_filename => Chef::Config[:client_key]
nodes = [
# { name: 'pccdevrap07-a', fqdn: 'pccdevrap07-a.domain.com', ipaddress: '10.0.1.177' },
{ name: 'pccdevrap07-m', fqdn: 'pccdevrap07-m.domain.com', ipaddress: '10.0.1.178' },
{ name: 'pccdevrap07-r', fqdn: 'pccdevrap07-r.domain.com', ipaddress: '10.0.1.179' }
]
nodes.each do |item|
template File.join(Chef::Config.file_cache_path, 'cloud-init.ps1') do
variables(computername: item[:name].upcase)
action :create
end.run_action(:create)
machine item[:name] do
name item[:name]
chef_environment "_default"
allow_overwrite_keys false
recipe 'pcc_site'
files 'C:/chef/encrypted_data_bag_secret' => {
local_path: File.expand_path("~/.chef/encrypted_data_bag")
}
attributes(
omnibus_updater: {
kill_chef_on_upgrade: false
}
)
machine_options(
install_msi_url: 'https://www.opscode.com/chef/install.msi',
is_windows: true,
use_private_ip_for_ssh: true,
bootstrap_options: {
key_name: 'keyname',
image_id: 'ami-id',
flavor_id: 'm3.medium',
vpc_id: 'vpc-id',
subnet_id: 'subnet-id',
security_group_ids: ['sg-group'],
iam_instance_profile: 'default',
iam_instance_profile_arn: 'profile',
dns_name: item[:fqdn],
private_dns_name: item[:fqdn],
tags: { 'Name' => item[:name].upcase },
block_device_mapping: [
{ 'DeviceName' => '/dev/sda1', 'VirtualName' => '/dev/sda1', 'Ebs.VolumeSize' => 40 },
],
private_ip_address: item[:ipaddress],
user_data: File.read(File.join(Chef::Config.file_cache_path, 'cloud-init.ps1')),
}
)
converge false
if ENV['DESTROY']
action :destroy
else
action :converge
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment