From e78b965a483ad2ef64bfd355bdeea659d186085b Mon Sep 17 00:00:00 2001 From: JJ Asghar Date: Thu, 24 Aug 2017 22:34:37 -0500 Subject: [PATCH 1/2] WIP: inital vmware addition Signed-off-by: JJ Asghar --- .kitchen.yml | 31 ++++++++++++++++++++++++ attributes/vmware.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++ recipes/_packer.rb | 9 +++++++ 3 files changed, 96 insertions(+) create mode 100644 attributes/vmware.rb diff --git a/.kitchen.yml b/.kitchen.yml index d40d819..64c9c35 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -40,6 +40,7 @@ suites: enabled: true compliance: enabled: true + - name: gce_compliance run_list: "marketplace_image::default" attributes: @@ -64,6 +65,30 @@ suites: compliance: enabled: true + - name: vmware_compliance + run_list: "marketplace_image::default" + attributes: + marketplace_image: + vmware: + compliance: + enabled: true + - name: vmware_automate + run_list: "marketplace_image::default" + attributes: + marketplace_image: + vmware: + automate: + enabled: true + - name: vmware_all + run_list: "marketplace_image::default" + attributes: + marketplace_image: + gce: + automate: + enabled: true + compliance: + enabled: true + - name: aws_public_automate run_list: "marketplace_image::default" attributes: @@ -131,6 +156,7 @@ suites: enabled: true compliance: enabled: true + - name: all run_list: "marketplace_image::default" attributes: @@ -156,3 +182,8 @@ suites: enabled: true compliance: enabled: true + vmware: + automate: + enabled: true + compliance: + enabled: true diff --git a/attributes/vmware.rb b/attributes/vmware.rb new file mode 100644 index 0000000..c761582 --- /dev/null +++ b/attributes/vmware.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true +default['marketplace_image']['vmware']['aio']['enabled'] = false +default['marketplace_image']['vmware']['compliance']['enabled'] = false + +cred_dir = ::File.expand_path(::File.join('~', '.vmware')) +account_file = ::File.join(cred_dir, 'account.json') + +default['marketplace_image']['vmware']['cred_dir'] = cred_dir +default['marketplace_image']['vmware']['account_file'] = account_file + +default_marketplace_config = { + 'role' => 'aio', + 'platform' => 'vmware', + 'support_email' => 'cloud-marketplaces@chef.io', + 'reporting_cron_enabled' => true, + 'doc_url' => 'https://docs.chef.io/google_marketplace.html', + 'disable_outbound_traffic' => false, + 'license_count' => 25, + 'license_type' => 'fixed', + 'free_node_count' => 5, +} + +vmware_builder_config = { + 'type' => 'vmware', + 'account_file' => node['marketplace_image']['vmware']['account_file'], + 'source_image' => 'centos7-template', + 'ssh_username' => 'root' # required on CentOS +} + +default['marketplace_image']['vmware']['aio']['products'] = + [5, 25, 50, 100, 150, 200, 250].map do |node_count| + { + 'name' => "vmware_aio_#{node_count}", + 'builder_options' => vmware_builder_config.merge( + 'image_name' => "Chef_AIO_#{node_count}_{{timestamp}}" + ), + 'marketplace_config_options' => default_marketplace_config.merge( + 'license_count' => node_count + ), + } + end + +default['marketplace_image']['vmware']['compliance']['products'] = + [5, 25, 50, 100, 150, 200, 250].map do |node_count| + { + 'name' => "vmware_compliance_#{node_count}", + 'builder_options' => vmware_builder_config.merge( + 'image_name' => "Chef_Compliance_#{node_count}_{{timestamp}}" + ), + 'marketplace_config_options' => default_marketplace_config.merge( + 'license_count' => node_count, + 'role' => 'compliance', + 'doc_url' => 'https://docs.chef.io/install_compliance.html#vmware' + ), + } + end diff --git a/recipes/_packer.rb b/recipes/_packer.rb index e8b2d68..2c79c79 100644 --- a/recipes/_packer.rb +++ b/recipes/_packer.rb @@ -40,3 +40,12 @@ content JSON.pretty_generate(creds['gce']['account']) end end + +if creds['vmware'] + directory node['marketplace_image']['vmware']['cred_dir'] + + file node['marketplace_image']['vmware']['account_file'] do + sensitive true + content JSON.pretty_generate(creds['vmware']['account']) + end +end From 9301bd471d2111b66a6f5d3a004927219bb49d71 Mon Sep 17 00:00:00 2001 From: Nolan Davidson Date: Wed, 20 Sep 2017 23:27:00 -0400 Subject: [PATCH 2/2] More work towards ova builds Signed-off-by: Nolan Davidson --- .kitchen.yml | 8 ++++- Berksfile | 2 +- attributes/vmware.rb | 37 ++++++++++++++----- libraries/helpers.rb | 26 ++++++++++++-- metadata.rb | 2 +- recipes/_packer.rb | 17 +++++++++ templates/default/ks.cfg | 78 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 157 insertions(+), 13 deletions(-) create mode 100644 templates/default/ks.cfg diff --git a/.kitchen.yml b/.kitchen.yml index 64c9c35..e207989 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -75,6 +75,12 @@ suites: - name: vmware_automate run_list: "marketplace_image::default" attributes: + vmware: + packer_ssh_password: <%= ENV['PACKER_SSH_PASSWORD'] %> + esx_host: <%= ENV['ESX_HOST'] %> + esx_password: <%= ENV['ESX_PASSWORD'] %> + packman: + version: '1.1.0' marketplace_image: vmware: automate: @@ -83,7 +89,7 @@ suites: run_list: "marketplace_image::default" attributes: marketplace_image: - gce: + vmware: automate: enabled: true compliance: diff --git a/Berksfile b/Berksfile index badae42..640b271 100644 --- a/Berksfile +++ b/Berksfile @@ -1,7 +1,7 @@ # frozen_string_literal: true source 'https://supermarket.chef.io' -cookbook 'fancy_execute', git: 'https://github.com/irvingpop/fancy_execute.git' +#cookbook 'fancy_execute', git: 'https://github.com/irvingpop/fancy_execute.git' cookbook 'packman', git: 'https://github.com/chef-partners/packman.git' metadata diff --git a/attributes/vmware.rb b/attributes/vmware.rb index c761582..efbf706 100644 --- a/attributes/vmware.rb +++ b/attributes/vmware.rb @@ -2,6 +2,8 @@ default['marketplace_image']['vmware']['aio']['enabled'] = false default['marketplace_image']['vmware']['compliance']['enabled'] = false +override['packman']['checksums']['1.1.0'] = 'bd1eddfa114f7e6258ef3419613380297f1b4e438f5bae92f1177150519be934' + cred_dir = ::File.expand_path(::File.join('~', '.vmware')) account_file = ::File.join(cred_dir, 'account.json') @@ -21,19 +23,38 @@ } vmware_builder_config = { - 'type' => 'vmware', - 'account_file' => node['marketplace_image']['vmware']['account_file'], - 'source_image' => 'centos7-template', - 'ssh_username' => 'root' # required on CentOS + 'type' => 'vmware-iso', + 'iso_url' => 'http://mirror.rackspace.com/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1708.iso', + 'iso_checksum' => 'bba314624956961a2ea31dd460cd860a77911c1e0a56e4820a12b9c5dad363f5', + 'iso_checksum_type' => 'sha256', + 'ssh_username' => 'root', + 'ssh_password' => node['vmware']['packer_ssh_password'], + 'ssh_wait_timeout' => '30m', + 'floppy_files' => [ + '/tmp/ks.cfg' + ], + 'boot_command' => ' inst.text inst.ks=hd:fd0:/ks.cfg ', + 'shutdown_command' => 'shutdown -P now', + 'remote_type' => 'esx5', + 'remote_host' => node['vmware']['esx_host'], + 'remote_username' => 'root', + 'remote_password' => node['vmware']['esx_password'], + 'vnc_disable_password' => 'true', + 'format' => 'ova', + 'vmx_data' => { + 'ethernet0.networkName' => 'VM Network' + } } default['marketplace_image']['vmware']['aio']['products'] = - [5, 25, 50, 100, 150, 200, 250].map do |node_count| + #[5, 25, 50, 100, 150, 200, 250].map do |node_count| + [250].map do |node_count| { 'name' => "vmware_aio_#{node_count}", - 'builder_options' => vmware_builder_config.merge( - 'image_name' => "Chef_AIO_#{node_count}_{{timestamp}}" - ), + 'builder_options' => vmware_builder_config, + #'builder_options' => vmware_builder_config.merge( + # 'image_name' => "Chef_AIO_#{node_count}_{{timestamp}}" + #), 'marketplace_config_options' => default_marketplace_config.merge( 'license_count' => node_count ), diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 13bde50..257bb42 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -19,11 +19,11 @@ module MarketplaceImageCookbook module Helpers def marketplace_products - aws_products + azure_products + gce_products + aws_products + azure_products + gce_products + vmware_products end def enabled_products - enabled_aws_products + enabled_azure_products + enabled_gce_products + enabled_aws_products + enabled_azure_products + enabled_gce_products + enabled_vmware_products end def enabled_builders @@ -110,6 +110,28 @@ def enabled_gce_products products end + def vmware_products + node['marketplace_image']['vmware']['aio']['products'] + + node['marketplace_image']['vmware']['compliance']['products'] + end + + def enabled_vmware_products + products = [] + products += node['marketplace_image']['vmware']['aio']['products'] if + node['marketplace_image']['vmware']['automate']['enabled'] + products += node['marketplace_image']['vmware']['compliance']['products'] if + node['marketplace_image']['vmware']['compliance']['enabled'] + products + end + + def vmware_builders + vmware_products.map { |p| p['name'] } + end + + def enabled_vmware_image_names + enabled_vmware_products.map { |p| p['builder_options']['image_name'] } + end + def enabled_gce_image_names enabled_gce_products.map { |p| p['builder_options']['image_name'] } end diff --git a/metadata.rb b/metadata.rb index fde7dda..0fa083a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -10,4 +10,4 @@ chef_version '>=12.19' depends 'packman' -depends 'fancy_execute', '~> 2.0' +#depends 'fancy_execute', '~> 2.0' diff --git a/recipes/_packer.rb b/recipes/_packer.rb index 2c79c79..25c99ab 100644 --- a/recipes/_packer.rb +++ b/recipes/_packer.rb @@ -48,4 +48,21 @@ sensitive true content JSON.pretty_generate(creds['vmware']['account']) end + + template '/tmp/ks.cfg' do + source 'ks.cfg' + variables({ + :root_password => node['vmware']['packer_ssh_password'] + }) + end + + remote_file '/tmp/ovftool.bundle' do + source 'https://s3-us-west-2.amazonaws.com/sce-pub/VMware-ovftool-4.2.0-5965791-lin.x86_64.bundle' + mode '0755' + end + + #execute 'install-ovftool' do + # cwd '/tmp' + # command './ovftool.bundle --eulas-agreed' + #end end diff --git a/templates/default/ks.cfg b/templates/default/ks.cfg new file mode 100644 index 0000000..a09ba2e --- /dev/null +++ b/templates/default/ks.cfg @@ -0,0 +1,78 @@ +install +cdrom +lang en_US.UTF-8 +keyboard us +unsupported_hardware +network --bootproto=dhcp +rootpw <%= @root_password %> +firewall --disabled +selinux --disabled +timezone UTC +unsupported_hardware +bootloader --location=mbr +text +skipx +zerombr +clearpart --all --initlabel +autopart +auth --enableshadow --passalgo=sha512 --kickstart +firstboot --disabled +eula --agreed +services --enabled=NetworkManager,sshd +reboot + +%packages --ignoremissing --excludedocs +@Base +@Core +openssh-clients +sudo +openssl-devel +readline-devel +zlib-devel +kernel-headers +kernel-devel +net-tools +vim +wget +curl +rsync + +# unnecessary firmware +-aic94xx-firmware +-atmel-firmware +-b43-openfwwf +-bfa-firmware +-ipw2100-firmware +-ipw2200-firmware +-ivtv-firmware +-iwl100-firmware +-iwl1000-firmware +-iwl3945-firmware +-iwl4965-firmware +-iwl5000-firmware +-iwl5150-firmware +-iwl6000-firmware +-iwl6000g2a-firmware +-iwl6050-firmware +-libertas-usb8388-firmware +-ql2100-firmware +-ql2200-firmware +-ql23xx-firmware +-ql2400-firmware +-ql2500-firmware +-rt61pci-firmware +-rt73usb-firmware +-xorg-x11-drv-ati-firmware +-zd1211-firmware +%end + +%post +yum update -y + +# update root certs +wget -O/etc/pki/tls/certs/ca-bundle.crt http://curl.haxx.se/ca/cacert.pem + +# sudo +yum install -y sudo +yum clean all +%end