GithubHelp home page GithubHelp logo

chef-boneyard / chef-provisioning Goto Github PK

View Code? Open in Web Editor NEW
524.0 107.0 170.0 1.23 MB

A library for creating machines and infrastructures idempotently in Chef.

License: Apache License 2.0

Ruby 99.74% Shell 0.26%

chef-provisioning's Introduction

Chef Provisioning was officially end-of-life on August 31, 2019 and is no longer included with Chef DK. The Chef Provisioning source code and drivers have been moved into the chef-boneyard organization. If you are a current user of Chef Provisioning, please contact your Chef Customer Success Manager or Account Representative to review your options.

Chef Provisioning

Status Gem Version

Please join us in Slack by signing up at http://community-slack.chef.io/ and joining #chef-provisioning

Overview

Chef Provisioning is a Cookbook and Recipe based approach for managing your infrastructure. Users can codify their infrastructure and use Chef to converge their infrastructure to the desired state. It has a plugin model (called Drivers) to manage different infrastructures, including AWS, Azure and Fog.

Chef Provisioning is maintained according to the Chef Maintenance Policy.

Drivers

Due to the age and engagement level with different Drivers they have fallen into two categories - maintained and unmaintained.

Maintained drivers have a representative in the maintenance policy and get triaged / discussed during office hours. They are

AWS Fog
Gem Version Gem Version

Maintained by Chef-Partners:

Maintained, not by Chef:

Unmaintained Drivers are at risk of becoming stale. They are:

Target Audience

Chef Provisioning is a good fit for people who use or want to use the Chef ecosystem to manage their infrastructure. Infrastructure is represented as Chef Resources and managed in Chef Recipes and Cookbooks. These recipes run on a provisioner node and attempt to converge the infrastructure idempotently. The AWS driver is the most used, the most tested and receives the most updates.

Chef Provisioning and its Drivers are maintained by the open source community. They currently have a slow tempo for issue triage and pull request merging. Troubleshooting a bug may require stepping through the Ruby Chef codebase and engaging the community.

If you are new to Chef and Chef Provisioning, learning both can be daunting. If you are not familiar with Ruby as well, double the learning curve. Successful provisioning users know how they want to manage their cookbooks. Generally this is some CI/CD pipeline.

Chef is very flexible which allows customized provisioning solutions at the cost of high complexity. This makes it hard to document all the possible use cases. Patterns (for example, how to manage the provisioning node and run the provisioning recipes) are not well documented.

Chef Provisioning should be used to manage infrastructure (CRUD operations) and register Chef nodes with the server for the first time only. Other use cases (like scheduling chef runs, node inventory or reporting) are not supported.

Documentation

These are the primary documents to help learn about using Provisioning and creating Provisioning drivers:

Media

This video explains the basics of chef-provisioning (though provisioners are now called drivers). Slides (more up to date) are here.

Date Blog
2014-12-15 Using Chef Provisioning to Build Chef Server
2014-11-12 Chef Launches Policy-Based Provisioning
2014-11-12 Chef Provisioning: Infrastructure As Code
2014-06-03 machine_batch and parallelization
2014-06-03 Chef Provisioning, Configuration and Drivers
2014-03-04 Chef Metal 0.2: Overview - this is a pretty good overview (though dated).
2013-12-20 Chef Metal Alpha

Try It Out

You can try out Chef Provisioning in many different flavors.

Vagrant

To give it a spin, install the latest ChefDK, Vagrant and VirtualBox. Run the following from the chef-provisioning/docs/examples directory:

export CHEF_DRIVER=vagrant
export VAGRANT_DEFAULT_PROVIDER=virtualbox
chef-client -z vagrant_linux.rb simple.rb

This will create two vagrant precise64 linux boxes, "mario" and "luigi1", in ~/machinetest, bootstrapped to an empty runlist. For Windows, you can replace myapp::linux with myapp::windows, but you'll need your own Windows vagrant box to do that (licensing!).

AWS

If you have an AWS account, you can spin up a machine there like this:

export CHEF_DRIVER=aws
chef-client -z simple.rb

This will create two linux boxes in the AWS account referenced by your default profile in ~/.aws/config (or your environment variables).

DigitalOcean

If you are on DigitalOcean and using the tugboat gem, you can do this:

export CHEF_DRIVER=fog:DigitalOcean
chef-client -z simple.rb

If you aren't using the tugboat gem, you can put driver and driver_options into your .chef/knife.rb file.

This will use your tugboat settings to create whatever sort of instance you normally create.

Cleaning up

When you are done with the examples, run this to clean up:

chef-client -z destroy_all.rb

What Is Chef Provisioning?

Chef Provisioning has two major abstractions: the machine resource, and drivers.

The machine resource

You declare what your machines do (recipes, tags, etc.) with the machine resource, the fundamental unit of Chef Provisioning. You will typically declare machine resources in a separate, OS/provisioning-independent file that declares the topology of your app--your machines and the recipes that will run on them.

The machine resources from the cluster.rb example are pretty straightforward. Here's a copy/paste:

# Database!
machine 'mario' do
  recipe 'postgresql'
  recipe 'mydb'
  tag 'mydb_master'
end

num_webservers = 1

# Web servers!
1.upto(num_webservers) do |i|
  machine "luigi#{i}" do
    recipe 'apache'
    recipe 'mywebapp'
  end
end

You will notice the dynamic nature of the number of web servers. It's all code, your imagination is the limit :)

Drivers

Drivers handle the real work of getting those abstract definitions into real, physical form. They handle the following tasks, idempotently (you can run the resource again and again and it will only create the machine once--though it may notice things are wrong and fix them!):

  • Acquiring machines from the cloud, creating containers or VMs, or grabbing bare metal
  • Connecting to those machines via ssh, winrm, or other transports
  • Bootstrapping chef onto the machines and converging the recipes you suggested

The driver API is separated out so that new drivers can be made with minimal effort (without having to rewrite ssh, tunneling, bootstrapping, and OS support). But to the user, they appear as a single thing, so that the machine acquisition can use its smarts to autodetect the other bits (transports, OS's, etc.).

Drivers save their data in the Chef node itself, so that they will be accessible to everyone who is using the Chef server to manage the nodes.

Machine options

You can pass machine options that will be used by machine, machine_batch and machine_image to configure the machine:

with_machine_options({
  convergence_options: {
    chef_version: "12.4.1",
    prerelease: false,
    chef_client_timeout: 120*60, # Default: 2 hours
    chef_config: { :log_level => :debug }, # Hash containing additional options to inject into client.rb, or String containing additional text to inject into client.rb
    chef_server: "http://my.chef.server/", # TODO could conflict with https://github.com/chef/chef-provisioning#pointing-boxes-at-chef-servers
    bootstrap_proxy: "http://localhost:1234",
    bootstrap_no_proxy: "localhost, *.example.com, my.chef.server",
    rubygems_url: "http://mirror.example.org",
    ssl_verify_mode: :verify_peer,
    client_rb_path: "/etc/chef/client.rb", # <- DEFAULT, overwrite if necessary
    client_pem_path: "/etc/chef/client.pem", # <- DEFAULT, overwrite if necessary
    allow_overwrite_keys: false, # If there is an existing client.pem this needs to be true to overwrite it
    private_key_options: {}, # TODO ????? Something to do with creating node object
    source_key: "", # ?????
    source_key_pass_phrase: "", # ?????
    source_key_path: "", # ?????
    public_key_path: "", # ?????
    public_key_format: "", # ?????
    admin: "", # ?????
    validator: "", # ?????
    ohai_hints: { :ec2 => { :key => :value } }, # Map from hint file name to file contents, this would create /etc/chef/ohai/hints/ec2.json,
    ignore_failure: [1, 5..10, SomeSpecificError], # If true don't let a convergence failure on provisioned machine stop the provisioning workstation converge.  Can also provide a single exit code to ignore (no array) or `true` to ignore all RuntimeErrors
    # The following are only available for Linux machines
    install_sh_url: "https://www.chef.io/chef/install.sh", # <- DEFAULT, overwrite if necessary
    install_sh_path: "/tmp/chef-install.sh", # <- DEFAULT, overwrite if necessary
    install_sh_arguments: "-P chefdk", # Additional commands to pass to install.sh
    # The following are only available for Windows machines
    install_msi_url: "foo://bar.com"
  },
  ssh_username: "ubuntu", # Username to use for ssh and WinRM
  ssh_gateway: "user@gateway", # SSH gateway configuration
  ssh_options: { # a list of options to Net::SSH.start
    :auth_methods => [ 'publickey' ], # DEFAULT
    :keys_only => true, # DEFAULT
    :host_key_alias => "#{instance.id}.AWS", # DEFAULT
    :key_data => nil, # use key from ssh-agent instead of a local file; remember to ssh-add your keys!
    :forward_agent => true, # you may want your ssh-agent to be available on your provisioned machines
    :never_forward_localhost => false, # This will, if set, disable SSH forwarding if it does not work/make sense in your envirnoment
    :remote_forwards => [
        # Give remote host access to squid proxy on provisioning node
        {:remote_port => 3128, :local_host => 'localhost', :local_port => 3128,},
        # Give remote host access to private git server
        {:remote_port => 2222, :local_host => 'git.example.com', :local_port => 22,},
    ],
    # You can send net-ssh log info to the Chef::Log if you are having
    # trouble with ssh.
    :logger => Chef::Log,
    # If you use :logger => Chef::Log and :verbose then your :verbose setting
    # will override the global Chef::Config. Probably don't want to do this:
    #:verbose => :warn,
  }
})

This options hash can be supplied to either with_machine_options or directly into the machine_options attribute.

Individual drivers will often add their own driver specific config. For example, AWS expects a :bootstrap_options hash at the same level as :convergence_options.

Anatomy of a Recipe

The ChefDK comes with a provisioner for Vagrant, an abstraction that covers VirtualBox, VMware and other Virtual Machine drivers. In docs/examples, you can run this to try it:

export CHEF_DRIVER=vagrant
export VAGRANT_DEFAULT_PROVIDER=virtualbox
chef-client -z vagrant_linux.rb simple.rb

To use with VMware, simply update the prior example to read export VAGRANT_DEFAULT_PROVIDER=vmware_fusion

This is a chef-client run, which runs multiple recipes. Chef Provisioning is nothing but resources you put in recipes.

The driver is specified on the command line. Drivers are URLs. You could use vagrant:~/vms or `fog:AWS:default:us-east-1' as driver URLs. More information here.

The vagrant_linux.rb recipe handles the physical specification of the machines and Vagrant box:

require 'chef/provisioning/vagrant_driver'

vagrant_box 'precise64' do
  url 'http://files.vagrantup.com/precise64.box'
end

with_machine_options :vagrant_options => {
  'vm.box' => 'precise64'
}

require 'chef/provisioning/vagrant_driver' is how we bring in the vagrant_box resource.

vagrant_box makes sure a particular vagrant box exists, and lets you specify machine_options for things like port forwarding, OS definitions, and any other vagrant-isms.

Typically, you declare these in separate files from your machine resources. Chef Provisioning picks up the drivers and machine_options you have declared, and uses them to instantiate the machines you request. The actual machine definitions, in this case, are in simple.rb, and are generic--you could use them against Azure or EC2 as well:

machine 'mario' do
  tag 'itsame'
end

Other directives, like recipe 'apache', help you set run lists and other information about the machine.

Pointing Boxes at Chef Servers

By default, Chef Provisioning will put your boxes on the same Chef server you started chef-client with (in the case of -z, that's a local chef-zero server). Sometimes you want to put your boxes on different servers. There are a couple of ways to do that:

with_chef_local_server :chef_repo_path => '~/repo'

with_chef_local_server is a generic directive that creates a chef-zero server pointed at the given repository. nodes, clients, data bags, and all data will be stored here on your provisioner machine if you do this.

You can use with_chef_server instead if you want to point at OSS, Hosted or Enterprise Chef, and if you don't specify a Chef server at all, it will use the one you are running chef-client against. Keep in mind when using with_chef_server and running chef-client -z on your workstation that you will also need to set the client name and signing key for the chef server. If you've already got knife.rb set up, then something like this in the provisioning recipe will correctly create a client for the chef server on instance using your knife.rb configuration:

with_chef_server "https://chef-server.example.org",
:options =>{  
  :client_name => Chef::Config[:node_name],
  :signing_key_filename => Chef::Config[:client_key]
  }

Finally, you can specify a Chef Server for an individual machine by using the chef_server attribute. This attribute takes the same additional options (:client_name, :signing_key_filename) that with_chef_server does.

machine 'mario' do
  chef_server :chef_server_url => "https://chef-server.example.org"
end

Configuring ACLs

If you want to run your provisionning recipes from an actual chef node, rather than from your workstation, you need to give that node's client enough rights to create the node and client he'll be provisioning on the chef server. Without those additional rights, the provisioning will fail with a error along the lines of chef_client[mymachine] had an error: Net::HTTPServerException: 403 "Forbidden".

A clean solution to this problem is to use knife-acl to define a provisioners group with the required rights, and add your client to it:

$> chef gem install knife-acl
$> knife group create provisioners
$> knife acl add group provisioners containers clients read,create,update,delete,grant
$> knife acl add group provisioners containers nodes read,create,update,delete,grant
$> knife group add client my_provisioning_client_name provisioners

Bugs and The Plan

Please submit bugs, gripes and feature requests at https://github.com/chef/chef-provisioning/issues and join us in the Slack room to chat.

To contribute, just make a PR in the appropriate repo following the Chef contribution process.

chef-provisioning's People

Contributors

andrewelizondo avatar andrewgoktepe avatar bdupras avatar bookshelfdave avatar chef-ci avatar dafyddcrosby avatar fnichol avatar glennmatthews avatar hh avatar jjlimepoint avatar jkeiser avatar johnewart avatar lamont-granquist avatar marcusn avatar mattvonvielen avatar miguelcnf avatar mivok avatar mrmmorris avatar mwrock avatar paustin01 avatar poliva83 avatar randomcamel avatar ranjib avatar sigusr2 avatar srb3 avatar stephenking avatar tas50 avatar tyler-ball avatar viglesiasce avatar waffle-iron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chef-provisioning's Issues

'action :converge_only' exception

For a machine created earlier via chef-metal with a different run_list.

machine 'blah' do
   recipe 'mycookbook::restart_services'
   action :converge_only
end

Throws exception:

DEBUG: NoMethodError: machine_batch[default] (@recipe_files::/Users/dinu/.chef/h/cookbooks/metal_restart.rb line 81) had an error: NoMethodError: private method `connect_to_machine' called for #<ChefMetal::ChefRunData:0x007fb7dc5a8de0>

Full stacktrace: http://pastebin.com/5MC1GpDv

machine converge action fails with chef-zero

when running the machine resource with just the converge action while running chef-zero i am receiving the error below, and what appears to be happening is the port isn't getting forwarded as it does with the create action. more succinctly, the make_url_available_to_remote method from Transport::Ssh class doesn't appear to ever get fired, so nobodies home on the client when trying to talk to localhost 8900.

i've tested using both the vagrant provisioner and an ssh provisioner i've written with same result.

i patched up the machine provider, basic_machine and cached convergence_strategy files and got it to work by passing the machine_resource through in the same way setup_convergence does and adding the make_url_available_to_remote in the same way that is utilized as well.

the working patched branch can be seen here:

https://github.com/double-z/chef-metal/tree/feature-machine-converge-action/lib

my question is is am doing something wrong on this and thus receiving the error, or is this a bug. and if a bug, is this a suitable way to patch? it's incomplete regardless, but is it how within metal it would be approached?

here's the output from the run, create action works fine:

vagrant@master:/vagrant/test$ ./run_zero both
Both Machines
[2014-04-08T22:08:39+00:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 11.10.4
[2014-04-08T22:08:40+00:00] WARN: Run List override has been provided.
[2014-04-08T22:08:40+00:00] WARN: Original Run List: []
[2014-04-08T22:08:40+00:00] WARN: Overridden Run List: [recipe[ssh_test::both]]
resolving cookbooks for run list: ["ssh_test::both"]
Synchronizing Cookbooks:

Chef encountered an error attempting to load the node data for "one"

Networking Error:

Connection refused - Connection refused connecting to http://127.0.0.1:8900/nodes/one, giving up

Your chef_server_url may be misconfigured, or the network could be down.

Relevant Config Settings:

chef_server_url "http://127.0.0.1:8900"

[2014-04-08T22:09:07+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 25.421401553 seconds
[2014-04-08T22:09:07+00:00] ERROR: Connection refused - Connection refused connecting to http://127.0.0.1:8900/nodes/one, giving up
[2014-04-08T22:09:08+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Less SSH Trash output

[2014-06-17T17:30:00-04:00] INFO: Executing sudo pwd on [email protected]

Comes a lot on the screen when it's waiting for SSH to come up, but it's pretty useless information to someone just running things. Is anyone interested in suppressing this output or removing it in favor of just dots in a line or something?

Error executing action `converge` on resource 'machine_batch[default]' : Name Required

Similar to #51, when running converge on an openstack node, I get the following:

Error executing action `converge` on resource 'machine_batch[default]'                                                                                                                                                                                                  [6/1938]
================================================================================


ArgumentError
-------------
name is required for this operation


Resource Declaration:
---------------------
# In /Users/username/.chef/local-mode-cache/cache/cookbooks/test_metal/recipes/default.rb

 40: machine 'mario' do
 41:   # recipe 'apt'
 42:   name 'mario'
 43:   tag 'mydb_master'
 44:   action [:delete, :create]
 45: end



Compiled Resource:
------------------
# Declared in /Users/username/.chef/local-mode-cache/cache/cookbooks/test_metal/recipes/default.rb:40:in `from_file'

machine_batch("default") do
  action :converge
  retries 0
  retry_delay 2
  guard_interpreter :default
  machines [<machine[mario] @name: "mario" @noop: nil @before: nil @params: {} @provider: nil @allowed_actions: [:nothing, :create, :delete, :stop, :converge, :nothing, :create] @action: [:delete, :create] @updated: false @updated_by_last_action: false @supports: {} @igno
re_failure: false @retries: 0 @retry_delay: 2 @source_line: "/Users/username/.chef/local-mode-cache/cache/cookbooks/test_metal/recipes/default.rb:40:in `from_file'" @guard_interpreter: :default @elapsed_time: 0 @resource_name: :machine @chef_environment: nil @chef_server:
{:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"mike", :signing_key_filename=>"/Users/username/.chef/mike.pem"}} @provisioner: #<ChefMetalFog::FogProvisioner:0x007f839d803388 @compute_options={:provider=>"OpenStack", :openstack_api_key=>"*************************",
:openstack_username=>"username", :openstack_auth_url=>"https://os-identity.vip.slc.company.com:5443/v2.0/tokens", :openstack_tenant=>"username"}, @base_bootstrap_options={:flavor_ref=>7, :image_ref=>"df012c92-5eef-4080-aac3-fd83ab3f6ba8", :floating_ip=>nil, :security_groups=
>"default"}, @openstack_credentials=#<ChefMetal::OpenstackCredentials:0x007f839d8032c0 @credentials={:default=>{:openstack_username=>nil, :openstack_api_key=>nil, :openstack_tenant=>nil, :openstack_auth_url=>nil}}>, @key_pairs={"me"=><fog_key_pair[me] @name: "me" @noop: n
il @before: nil @params: {} @provider: nil @allowed_actions: [:nothing, :create, :delete, :nothing, :create] @action: :create @updated: false @updated_by_last_action: false @supports: {} @ignore_failure: false @retries: 0 @retry_delay: 2 @source_line: "/Users/username/.che
f/local-mode-cache/cache/cookbooks/test_metal/recipes/default.rb:33:in `from_file'" @guard_interpreter: :default @elapsed_time: 2.990792 @resource_name: :fog_key_pair @provisioner: #<ChefMetalFog::FogProvisioner:0x007f839d803388 ...> @cookbook_name: "test_metal" @recipe_n
ame: "default" @private_key_path: "/Users/username/openstack_test/me" @public_key_path: "/Users/username/openstack_test/me.pub" @private_key_options: nil>}, @base_bootstrap_options_for={<machine[mario] @name: "mario" @noop: nil @before: nil @params: {} @provider: nil @allow
ed_actions: [:nothing, :create, :delete, :stop, :converge, :nothing, :create] @action: [:delete, :create] @updated: false @updated_by_last_action: false @supports: {} @ignore_failure: false @retries: 0 @retry_delay: 2 @source_line: "/Users/username/.chef/local-mode-cache/c
ache/cookbooks/test_metal/recipes/default.rb:40:in `from_file'" @guard_interpreter: :default @elapsed_time: 0 @resource_name: :machine @chef_environment: nil @chef_server: {:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"mike", :signing_key_filename=>
"/Users/username/.chef/mike.pem"}} @provisioner: #<ChefMetalFog::FogProvisioner:0x007f839d803388 ...> @provisioner_options: {:flavor_ref=>7} @cookbook_name: "test_metal" @recipe_name: "default" @attribute_modifiers: [["tags", #<Proc:0x007f839cfeec60@/Users/username/.chefdk/
gem/ruby/2.1.0/gems/cheffish-0.4/lib/cheffish.rb:48>]] @complete: nil @raw_json: nil @run_list: nil @attributes: nil>=>{:flavor_ref=>7, :image_ref=>"df012c92-5eef-4080-aac3-fd83ab3f6ba8", :floating_ip=>nil, :security_groups=>"default", :key_name=>"me", :private_key_path=>
"/Users/username/openstack_test/me", :public_key_path=>"/Users/username/openstack_test/me.pub"}}, @compute=#<Fog::Compute::OpenStack::Real:70101618034080 @openstack_auth_token=nil @auth_token="7c25931f22e942efabbada52e8402fd9" @openstack_identity_public_endpoint="https://os
-identity.vip.slc.company.com:5443/v2.0" @openstack_api_key="*************************" @openstack_username="username" @openstack_tenant="username" @openstack_auth_uri=#<URI::HTTPS:0x007f839c151d38 URL:https://os-identity.vip.slc.company.com:5443/v2.0/tokens> @openstack_management_url="http
://os-compute.vip.slc01.company.com:8774/v2/4e5ad55b98304957af25adde0dae9414" @openstack_must_reauthenticate=false @openstack_service_type=["nova", "compute"] @openstack_service_name=nil @openstack_identity_service_type="identity" @openstack_endpoint_type="publicURL" @open
stack_region=nil @connection_options={:debug_response=>true, :headers=>{"User-Agent"=>"fog/1.22.0"}, :persistent=>false} @current_user={"username"=>"username", "roles_links"=>[], "id"=>"6a49fc5cdbb34f45bb1529db6138356a", "roles"=>[{"name"=>"Member"}], "name"=>"username"} @c
urrent_tenant={"id"=>"4e5ad55b98304957af25adde0dae9414", "enabled"=>true, "description"=>"", "name"=>"username", "creator"=>"6a49fc5cdbb34f45bb1529db6138356a"} @auth_token_expiration="2014-05-04T02:44:21Z" @host="os-compute.vip.slc01.company.com" @path="/v2" @tenant_id="4e5
ad55b98304957af25adde0dae9414" @port=8774 @scheme="http" @identity_connection=#<Fog::Core::Connection:0x007f839c183130 @excon=#<Excon::Connection:7f839c1821b8 @data={:chunk_size=>1048576, :ciphers=>"HIGH:!SSLv2:!aNULL:!eNULL:!3DES", :connect_timeout=>60, :debug_request=>f
alse, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.22.0"}, :idempotent=>false, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::ResponseParser, Excon::Middleware::Expects, Excon::Middleware::Idempotent, Excon::Middleware::Instrumentor, Excon::Middl
eware::Mock], :mock=>false, :nonblock=>true, :omit_default_port=>false, :persistent=>false, :read_timeout=>60, :retry_limit=>4, :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :write_timeout=>60, :host=>"os-identity.vip.slc.company.com", :path=>"/v2.0", :por
t=>5443, :query=>nil, :scheme=>"https", :user=>nil, :password=>nil} @socket_key="https://os-identity.vip.slc.company.com:5443">> @persistent=false @connection=#<Fog::Core::Connection:0x007f839c1805c0 @excon=#<Excon::Connection:7f839c18acf0 @data={:chunk_size=>1048576, :cip
hers=>"HIGH:!SSLv2:!aNULL:!eNULL:!3DES", :connect_timeout=>60, :debug_request=>false, :debug_response=>true, :headers=>{"User-Agent"=>"fog/1.22.0"}, :idempotent=>false, :instrumentor_name=>"excon", :middlewares=>[Excon::Middleware::ResponseParser, Excon::Middleware::Expec
ts, Excon::Middleware::Idempotent, Excon::Middleware::Instrumentor, Excon::Middleware::Mock], :mock=>false, :nonblock=>true, :omit_default_port=>false, :persistent=>false, :read_timeout=>60, :retry_limit=>4, :ssl_verify_peer=>true, :tcp_nodelay=>false, :uri_parser=>URI, :
write_timeout=>60, :host=>"os-compute.vip.slc01.company.com", :path=>"", :port=>8774, :query=>nil, :scheme=>"http", :user=>nil, :password=>nil} @socket_key="http://os-compute.vip.slc01.company.com:8774">>>> @provisioner_options: {:flavor_ref=>7} @cookbook_name: "test_metal"
 @recipe_name: "default" @attribute_modifiers: [["tags", #<Proc:0x007f839cfeec60@/Users/username/.chefdk/gem/ruby/2.1.0/gems/cheffish-0.4/lib/cheffish.rb:48>]] @complete: nil @raw_json: nil @run_list: nil @attributes: nil>]
  chef_server {:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"mike", :signing_key_filename=>"/Users/username/.chef/mike.pem"}}
  cookbook_name "test_metal"
  recipe_name "default"
end

Here's the full dump:

https://gist.github.com/mikesplain/29db18c9a8c5bc7a6d7d

chef-metal (0.10.2)
chef-metal-fog (0.4)

I tried adding a name parameter but it didn't seem to work. Not really sure how else to debug this. Thanks!

403 error when registering the new node as a client

Recipe for chef-metal on Rackspace here:

https://gist.github.com/hhoover/1c2518522b5e7818d4dc

The 'cloud2' machine is created as expected but I get this error when it tries to POST to Hosted Chef as a new client:

[IPADDR] chef_client[cloud2] (basic_chef_client::block line 133) had an error: Net::HTTPServerException: 403 "Forbidden"

It does register in the node list with the proper run_list. Not sure what I'm doing wrong. Any help is appreciated!

machine_file enhancement(s) request

As a chef-metal user, I want to upload files with security constraints to my machines. Currently the machine_file resource does not accept "mode", "owner", "group" so this is not possible.

Also it would be fantastic to have a "machine_directory" resource to match. Example use case, establishing SSH trusts:

  machine_directory '/root/.ssh' do
    owner 'root'
    group 'root'
    mode '0700'
    action :create
  end

  machine_file '/root/.ssh/authorized_keys' do
    content node['mycookbook']['root_ssh']['authorized_keys']
    machine vmname
    mode '0600'
    owner 'root'
    group 'root'
  end

chefspec tests see machines as machine_batch

I had a matcher helper for testing machipe recipes that looked like this:

if defined?(ChefSpec)
  ChefSpec::Runner.define_runner_method :machine

  def converge_machine(resource_name)
    ChefSpec::Matchers::ResourceMatcher.new(:machine, :converge, resource_name)
  end
end

an example it block is:

    it 'creates with the correct machine name' do
        expect(chef_run).to converge_machine(vm_name)
    end
    it 'creates with the second machine name' do
        expect(chef_run).to converge_machine(vm_name2)
    end
    it 'creates with the correct number of cpus' do
        expect(chef_run.machine(vm_name).machine_options[:bootstrap_options]['numCPUs']).to eq(expected_options[:numCPUs])
    end

These failed with the last beta (5). chef_run.machine is a machine_batch instance. I had to rewrite these tests as:

    it 'creates with the correct machine name' do
        expect(chef_run).to converge_machine(vm_name)
    end
    it 'creates second machine with the correct machine name' do
        machine_to_check = chef_run.machine(vm_name).machines
        expect(machine_to_check[1].name).to eq(vm_name2)
    end
    it 'creates with the correct number of cpus' do
        machine_to_check = chef_run.machine(vm_name).machines
        expect(machine_to_check[0].machine_options[:bootstrap_options]['numCPUs']).to eq(expected_options[:numCPUs])
        expect(machine_to_check[1].machine_options[:bootstrap_options]['numCPUs']).to eq(expected_options[:numCPUs])
    end

This is obviously a bit awkward and forces a symantic deviation between the test and recipe.

show machine chef-client run output - enhancement request

As a chef-metal user, I would like to see the output of my machine's chef-client runs under normal conditions, not just when there's an error. It's possible to do this now by using -l debug, but this spams the console with the "outer" chef-client run.

Some day when we support parallel provisioning of machines it would be nice to have colorized output like knife ssh.

Machines are converging twice

I'm running 0.11.beta.2 bits. and I'm using a custom vsphere driver that I have adapted from the fog driver. I retrofitted it over the weekend to conform to the new driver interface.

My issue is that the machine node runs 2 identical convergences after it is bootstrapped. Having traced through the code, this seems to be due to the fact that Chef-Metal invokes the converge action on both the machine and a machine_batch which is automatically created. Both convergences seem to have no awareness of one another.

I am currently very new to Chef and Ruby so it is entirely possible that something is wrong on my end or I am simply calling the API incorrectly.

I have created my own "provisioner_cluster" LWRP to encapsulate the my internal logic that finds vsphere resources to provision. The provider looks like this:

use_inline_resources

def whyrun_supported?
  true
end

action :create do
  cluster_resource = @new_resource
  dc_config = data_bag_item('datacenters', current_environment)
  hypervisor = dc_config['hypervisors'][cluster_resource.hypervisor_type][cluster_resource.hypervisor_idx]
  subnet = network_subnet(dc_config['network'])

  with_vsphere_driver :vsphere_server => hypervisor['vsphere_server'],
    :vsphere_username => hypervisor['vsphere_username'],
    :vsphere_password => hypervisor['vsphere_password'],
    :vsphere_expected_pubkey_hash => hypervisor['vsphere_expected_pubkey_hash'],
    :ssh_password => node['provisioner']['ssh_password']

  updated = true
  1.upto(cluster_resource.node_count) do |i|
    machine_name = machine_name_to_provision(cluster_resource.cluster_name, i)
    current_octet = cluster_resource.ip_start + (i - 1)
    if !cluster_resource.recipe.nil?
      recipe_to_run = cluster_resource.recipe['default']
      if cluster_resource.recipe.has_key?(current_octet)
        recipe_to_run = cluster_resource.recipe[current_octet]
      end
    end

    success = machine machine_name do
      machine_options :bootstrap_options => {
        'primary_dns' => dc_config['primary_dns'],
        'secondary_dns' => dc_config['secondary_dns'],
        'numCPUs' => cluster_resource.cpu_count,
        'memoryMB' => cluster_resource.memoryMB,
        'datacenter' => hypervisor['datacenter'],
        'dest_folder' => node['provisioner']['dest_folder'],
        'datastore' => hypervisor['datastores'][cluster_resource.storage_offset + (i-1)]['name'],
        'network_label' => dc_config['network'],
        'network_adapter_device_key' => node['provisioner']['network_adapter_device_key'],
        'resource_pool' => [hypervisor['clusters'][cluster_resource.hypervisor_cluster_idx], node['provisioner']['resource_pool']],
        'template_path' => cluster_resource.template,
        'additional_disk_size_gb' => cluster_resource.additional_disk_size_gb,
        'customization_spec' => {
          'ipsettings' => {
            'ip' => "#{subnet}.#{current_octet}",
            'subnetMask' => '255.255.255.0',
            'gateway' => ["#{subnet}.1"]
          },
          'domain' => 'local',
        }
      }
      attributes cluster_resource.attributes
      recipe recipe_to_run
      action :converge
    end
    if !success.updated_by_last_action?
      updated = false
    end
  end
  cluster_resource.updated_by_last_action(updated)
end

Is this a known bug or does it look like I'm doing this wrong?

Thanks!!

Xen server VM provisioner

Hi
I was very excited when I came across this project hoping it can simply and replace our current xen-provision cookbook which we use to create ubuntu VMs on our Xen servers.
But I am guessing that the Xen provisioner needs to be written first before I am really happy. :)
Any plans on that - do you know if someone is doing this?
It does not appear to be in your trello project though.
Thank in advance.

Failure with action :setup and machine_batch

When using machine_batch and action :setup, the chef run fails with ArgumentError. This is with ChefDK and chef-metal 0.11.1:

chef gem list chef-metal
WARN: Unresolved specs during Gem::Specification.reset:
      yajl-ruby (~> 1.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.

*** LOCAL GEMS ***

chef-metal (0.11.1)
chef-metal-fog (0.5.1)
chef-metal-vagrant (0.4)

Test recipe:

require 'chef_metal'

with_driver "vagrant:#{ENV['PWD']}/vms"
with_machine_options :vagrant_options => { 'vm.box' => 'hashicorp/precise64' }

machine_batch do
  machines 'test1'
  action :setup
end

I also did the following to make chef zero happy:

$ pwd
/Users/mark/scratch/metal_test
$ mkdir .chef
$ touch .chef/knife.rb

Output:

$ pwd
/Users/mark/scratch/metal_test
$ chef-client -z ./test.rb
[2014-06-09T15:18:52-04:00] WARN: No cookbooks directory found at or above current directory.  Assuming /Users/mark/scratch/metal_test.
[2014-06-09T15:18:52-04:00] WARN:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:

```
  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true
```

To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:

```
  knife ssl check -c /Users/mark/scratch/metal_test/.chef/knife.rb
```

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Starting Chef Client, version 11.14.0.alpha.1
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...
[2014-06-09T15:18:53-04:00] WARN: Node alioth.int.hex0.com has an empty run list.
Converging 1 resources
Recipe: @recipe_files::/Users/mark/scratch/metal_test/test.rb
  * machine_batch[default] action setup
    - [test1] create new directory /Users/mark/scratch/metal_test/vms
    - [test1] create new file /Users/mark/scratch/metal_test/vms/Vagrantfile
    - [test1] update content in file /Users/mark/scratch/metal_test/vms/Vagrantfile from none to bec226
    - [test1] --- /Users/mark/scratch/metal_test/vms/Vagrantfile    2014-06-09 15:18:54.000000000 -0400
    - [test1] +++ /var/folders/j7/psd9dvcd24x2wnjcsq8h8j500000gp/T/.Vagrantfile20140609-59973-1qnnvli   2014-06-09 15:18:54.000000000 -0400
    - [test1] @@ -1 +1,4 @@
    - [test1] +Dir.glob('/Users/mark/scratch/metal_test/vms/*.vm') do |vm_file|
    - [test1] +  eval(IO.read(vm_file), nil, vm_file)
    - [test1] +end
    - [test1] create new file /Users/mark/scratch/metal_test/vms/test1.vm
    - [test1] update content in file /Users/mark/scratch/metal_test/vms/test1.vm from none to 5f4123
    - [test1] --- /Users/mark/scratch/metal_test/vms/test1.vm   2014-06-09 15:18:54.000000000 -0400
    - [test1] +++ /var/folders/j7/psd9dvcd24x2wnjcsq8h8j500000gp/T/.test1.vm20140609-59973-v37y8t   2014-06-09 15:18:54.000000000 -0400
    - [test1] @@ -1 +1,7 @@
    - [test1] +Vagrant.configure('2') do |outer_config|
    - [test1] +  outer_config.vm.define "test1" do |config|
    - [test1] +    config.vm.box = "hashicorp/precise64"
    - [test1] +    config.vm.hostname = "test1"
    - [test1] +  end
    - [test1] +end
    - [test1] create node test1 at http://127.0.0.1:8889
    - [test1]   add normal.metal = {"location"=>{"driver_url"=>"vagrant:/Users/mark/scratch/metal_test/vms", "driver_version"=>"0.4", "vm_name"=>"test1", "vm_file_path"=>"/Users/mark/scratch/metal_test/vms/test1.vm", "allocated_at"=>"2014-06-09 19:18:54 UTC", "host_node"=>"http://127.0.0.1:8889/nodes/", "needs_reload"=>true}}
    - [test1]   add normal.tags = nil
    - run vagrant up --parallel test1 (status was 'not created')
    - update node test1 at http://127.0.0.1:8889
    -   update normal.metal.location.needs_reload from true to false
    -   add normal.metal.location.forwarded_ports = {}
================================================================================
Error executing action `setup` on resource 'machine_batch[default]'
================================================================================


ArgumentError
-------------
wrong number of arguments (0 for 1)


Resource Declaration:
---------------------
# In /Users/mark/scratch/metal_test/test.rb

  6: machine_batch do
  7:   machines 'test1'
  8:   action :setup
  9: end



Compiled Resource:
------------------
# Declared in /Users/mark/scratch/metal_test/test.rb:6:in `from_file'

machine_batch("default") do
  action [:setup]
  retries 0
  retry_delay 2
  guard_interpreter :default
  driver "vagrant:/Users/mark/scratch/metal_test/vms"
  chef_server {:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"alioth.int.hex0.com", :signing_key_filename=>nil}}
  machine_options {:vagrant_options=>{"vm.box"=>"hashicorp/precise64"}}
  cookbook_name "@recipe_files"
  recipe_name "/Users/mark/scratch/metal_test/test.rb"
  machines ["test1"]
end




Running handlers:
[2014-06-09T15:19:18-04:00] ERROR: Running exception handlers
Running handlers complete

[2014-06-09T15:19:18-04:00] ERROR: Exception handlers complete
[2014-06-09T15:19:18-04:00] FATAL: Stacktrace dumped to /Users/mark/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 25.471032 seconds
[2014-06-09T15:19:18-04:00] ERROR: machine_batch[default] (@recipe_files::/Users/mark/scratch/metal_test/test.rb line 6) had an error: ArgumentError: wrong number of arguments (0 for 1)
[2014-06-09T15:19:18-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Stack trace:

Generated at 2014-06-09 15:29:09 -0400
ArgumentError: machine_batch[default] (@recipe_files::/Users/mark/scratch/metal_test/test.rb line 6) had an error: ArgumentError: wrong number of arguments (0 for 1)
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef_metal/recipe_dsl.rb:63:in `machine'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:41:in `block (2 levels) in <class:MachineBatch>'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:90:in `block (2 levels) in with_ready_machines'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-vagrant-0.4/lib/chef_metal_vagrant/vagrant_driver.rb:126:in `block in ready_machines'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-vagrant-0.4/lib/chef_metal_vagrant/vagrant_driver.rb:123:in `each_pair'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-vagrant-0.4/lib/chef_metal_vagrant/vagrant_driver.rb:123:in `ready_machines'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:83:in `block in with_ready_machines'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/chef_fs/parallelizer.rb:95:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/chef_fs/parallelizer.rb:95:in `process_input'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/chef_fs/parallelizer.rb:70:in `each'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:102:in `to_a'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:102:in `parallel_do'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:82:in `with_ready_machines'
/Users/mark/.chefdk/gem/ruby/2.1.0/gems/chef-metal-0.11.1/lib/chef/provider/machine_batch.rb:39:in `block in <class:MachineBatch>'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/provider/lwrp_base.rb:60:in `instance_eval'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/provider/lwrp_base.rb:60:in `recipe_eval_with_update_check'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/provider/lwrp_base.rb:45:in `block in action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/provider.rb:121:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource.rb:638:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/runner.rb:49:in `run_action'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/runner.rb:81:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/runner.rb:81:in `block in converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection.rb:98:in `block in execute_each_resource'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/resource_collection.rb:96:in `execute_each_resource'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/runner.rb:80:in `converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/client.rb:345:in `converge'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/client.rb:431:in `do_run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/client.rb:213:in `block in run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/client.rb:207:in `fork'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/client.rb:207:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/application.rb:222:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/application/client.rb:328:in `block in run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/application/client.rb:317:in `loop'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/application/client.rb:317:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/lib/chef/application.rb:54:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/chef-11.14.0.alpha.1/bin/chef-client:26:in `<top (required)>'
/opt/chefdk/embedded/bin/chef-client:23:in `load'
/opt/chefdk/embedded/bin/chef-client:23:in `<main>'

This also happens with the AWS driver. Vagrant was just a simple test case.

Non-Ubuntu AWS SSH Does not work

I've tried setting the ssh_username in every imagine able way, but I cannot get the username ot change from ubuntu to ec2-user. Am I crazy or is this an actual bug?

machine 'Machine' do
    run_list ["recipe[tomcat]"]
    machine_options :bootstrap_options => {
            :image_id =>'ami-ed8e9284',
            :flavor_id => 'm3.medium',
            :availability_zone =>'us-east-1b',
            :key_name =>'cls-master-dev',
            :ssh_username => 'ec2-user',
            :private_key_path => 'something.pem',
            :groups => 'group'}
end

Automatically upload data bag secret key for each machine

Currently it is necessary to upload your encrypted_data_bag_secret file for each machine you create with either machine_file or file (within machine)

eg:

machine 'rabbitmq-01' do
  tag 'rabbitmq'
  recipe 'rabbitmq'
  converge true
  file "/etc/chef/encrypted_data_bag_secret", "#{ENV['HOME']}/.chef/encrypted_data_bag_secret"
end

It would be nice if when creating a machine the local location of the encrypted_data_bag_secret file was automatically discovered from the chef context metal was being run in and uploaded to the machine being created.

Unable to use Vagrant driver behind corporate http proxy

My http_proxy env vars are set properly but unless I'm missing some Vagrant driver specific config, I'm unable to setup a basic vagrant machine. It fails on getting the machine metadata. Please see the stacktrace below:

[2014-06-03T23:09:44-05:00] INFO: Executing sudo sh /tmp/detect.sh on [email protected]
PLATFORM: el
PLATFORM_VERSION: 6
MACHINE: x86_64
[2014-06-03T23:09:44-05:00] INFO: Completed sh /tmp/detect.sh on [email protected]: exit status 0
[2014-06-03T23:09:44-05:00] DEBUG: Getting metadata for machine jenkins: https://www.opscode.com/chef/metadata?v=&prerelease=false&p=el&pv=6&m=x86_64
[2014-06-03T23:09:44-05:00] DEBUG: Closing SSH session on [email protected]

================================================================================
Error executing action `converge` on resource 'machine_batch[default]'
================================================================================


SocketError
-----------
getaddrinfo: nodename nor servname provided, or not known


Resource Declaration:
---------------------
# In /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/recipe_dsl.rb

 81:             batch = build_resource(:machine_batch, machine_batch_default_name) do
 82:               action resource.action
 83:               machines [ previous, resource ]
 84:             end
 85:             batch.from_recipe self



Compiled Resource:
------------------
# Declared in /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/recipe_dsl.rb:81:in `machine'

machine_batch("default") do
  action [:converge]
  retries 0
  retry_delay 2
  guard_interpreter :default
  driver "vagrant:/Users/nick/machinetest"
  chef_server {:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"212406206", :signing_key_filename=>"/Users/nick/archops/.chef/212406206.pem"}}
  machine_options {:vagrant_options=>{"vm.box"=>"opscode-centos-6.4"}}
  cookbook_name "test"
  recipe_name "pipeline"
  machines ["jenkins", "docker"]
end



[2014-06-03T23:09:44-05:00] INFO: Running queued delayed notifications before re-raising exception
[2014-06-03T23:09:44-05:00] DEBUG: Re-raising exception: SocketError - machine_batch[default] (test::pipeline line 81) had an error: SocketError: getaddrinfo: nodename nor servname provided, or not known
/usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:763:in `initialize'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:763:in `open'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:763:in `block in connect'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:763:in `connect'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:745:in `start'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/net/http.rb:1285:in `request'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/convergence_strategy/install_cached.rb:124:in `download_metadata_for_platform'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/convergence_strategy/install_cached.rb:82:in `block in download_package_for_platform'
  <internal:prelude>:10:in `synchronize'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/convergence_strategy/install_cached.rb:77:in `download_package_for_platform'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/convergence_strategy/install_cached.rb:46:in `setup_convergence'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef_metal/machine/basic_machine.rb:16:in `setup_convergence'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:50:in `block (2 levels) in <class:MachineBatch>'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:89:in `block (2 levels) in with_ready_machines'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-vagrant-0.4.beta.2/lib/chef_metal_vagrant/vagrant_driver.rb:126:in `block in ready_machines'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-vagrant-0.4.beta.2/lib/chef_metal_vagrant/vagrant_driver.rb:123:in `each_pair'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-vagrant-0.4.beta.2/lib/chef_metal_vagrant/vagrant_driver.rb:123:in `ready_machines'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:82:in `block in with_ready_machines'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/chef_fs/parallelizer.rb:95:in `call'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/chef_fs/parallelizer.rb:95:in `process_input'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/chef_fs/parallelizer.rb:70:in `each'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:101:in `to_a'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:101:in `parallel_do'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:81:in `with_ready_machines'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-metal-0.11.beta.11/lib/chef/provider/machine_batch.rb:48:in `block in <class:MachineBatch>'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/provider/lwrp_base.rb:60:in `instance_eval'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/provider/lwrp_base.rb:60:in `recipe_eval_with_update_check'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/provider/lwrp_base.rb:45:in `block in action'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/provider.rb:120:in `run_action'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource.rb:637:in `run_action'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/runner.rb:49:in `run_action'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/runner.rb:81:in `block (2 levels) in converge'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/runner.rb:81:in `each'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/runner.rb:81:in `block in converge'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection.rb:98:in `block in execute_each_resource'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/resource_collection.rb:96:in `execute_each_resource'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/runner.rb:80:in `converge'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/client.rb:345:in `converge'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/client.rb:431:in `do_run'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/client.rb:213:in `block in run'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/client.rb:207:in `fork'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/client.rb:207:in `run'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/application.rb:217:in `run_chef_client'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/application/client.rb:328:in `block in run_application'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/application/client.rb:317:in `loop'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/application/client.rb:317:in `run_application'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/lib/chef/application.rb:67:in `run'
  /usr/local/var/rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/chef-11.12.4/bin/chef-client:26:in `<top (required)>'
  /usr/local/var/rbenv/versions/1.9.3-p545/bin/chef-client:23:in `load'
  /usr/local/var/rbenv/versions/1.9.3-p545/bin/chef-client:23:in `<main>'

machine resource inside of a machine_batch no longer respects not_if/only_if

For example from ec-metal:

  machine_batch 'cloud_create' do
    action [:converge]
    %w(backends frontends).each do |whichend|
      node['harness']['vm_config'][whichend].each do |vmname, config|

        machine vmname do
          add_machine_options node['harness']['provisioner_options'][vmname]
          attribute 'private-chef', privatechef_attributes
          attribute 'root_ssh', node['harness']['root_ssh'].to_hash
          attribute 'cloud', cloud_attributes('ec2')
          recipe 'private-chef::hostname'
          recipe 'private-chef::ec2'

          not_if { cloud_machine_created?(vmname) }
        end
      end
    end
  end

I verified that the cloud_machine_created? method isn't being called at all.

Minimum fog version suggestion ('ubuntu' user hardcoded in AWS SSH)

May want to specify a minimum fog version at some point somewhere. I just wasted several hours tracing a bug where in fog 1.15.0 the 'ubuntu' user was hardcoded for AWS SSH, and chef-client was picking up 1.15.0 instead of 1.21.0. Hope that saves someone else a few hours :-/

Not a bug in metal, but writing it down should someone else have this problem

Support for already-provisioned machines - enhancement request

I would like to run chef-metal on preexisting machines (Bare Metal, or manually provisioned VMs).

For existing machines, we would need some combination of:

  • root user + ssh key location
  • normal user + password (and assume the same password is used for sudo)

as well as the machine's hostname/IP.

Any reasons this is packaged as a gem and not HWRPs?

It seems to me that it would be easier to integrate, test, troubleshoot, etc. if chef-metal was a library cookbook that provided heavy-weight resource providers instead of a gem that provides the custom resources.

Initial chef-client run on workstation talking to hosted chef-server fails on creating client

I'm using the 0.11.beta2 version of chef-metal.

When I run the initial chef-client run on my workstation to create the machine, it seems to fail when it trys to create the client object on the hosted web server.

I'm guessing that my workstation chef-client doesn't have the permissions to create a new client?

Here's a gist with the last part of the chef-client run output:
https://gist.github.com/rberger/d4a37130dfd2f2869eec

Here's a gist with the stacktrace:
https://gist.github.com/rberger/745bc65fc803b6d91402

Setting up local mode when embedding chef-metal

I have an integration test for a chef-metal driver where I test creation and destruction of VMs. The test sets everything up outside of a cookbook environment. Having read the wiki on embedding chef-metal, my test setup looks like this:

    before :all do
        @vm_name = "cmvd-test-#{SecureRandom.hex}"
        @metal_config = eval File.read(File.expand_path('../config.rb', __FILE__))
        Cheffish.honor_local_mode do
            chef_server = Cheffish.default_chef_server(@metal_config)
            @machine_spec = ChefMetal::ChefMachineSpec.new({'name' => @vm_name}, chef_server)
            @driver = ChefMetal.driver_for_url("vsphere://#{@metal_config[:driver_options][:host]}", @metal_config)
            action_handler = ChefMetal::ActionHandler.new
            @driver.allocate_machine(action_handler, @machine_spec, @metal_config[:machine_options])
            @metal_config[:machine_options][:convergence_options] = {}
            @driver.ready_machine(action_handler, @machine_spec, @metal_config[:machine_options])
            @server_id = @machine_spec.location['server_id']
            @connection = vim(@metal_config[:driver_options])
            @vm = find_vm_by_id(@server_id, @connection)
        end
    end

This works great for testing creation. However, when destroying machines I get an InvalidURIError when the driver calls:

strategy.cleanup_convergence(action_handler, machine_spec)

because the chef server url is nil.

Shouldn't the url be set to the chef-zero url? Am I missing something in my setup?

provisioner_option directive overwrites defaults

I have chef-metal recipe that generates a default

Vagrant.configure('2') do |outer_config|
  outer_config.vm.define "chef-server" do |config|
    config.vm.hostname = "chef-server"
    config.vm.box = "opscode-ubuntu-10.04"
    config.vm.box_url = "http://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-10.04.box"
  end
end

I wanted sync'd folders. Since vagrant_options does not do statements, I have to use vagrant_config instead.

machine "chef-server" do
  tag 'chef-server'
  recipe 'chef-server'

  attribute %w(chef-server api_fqdn), 'chef-server.local'

  provisioner_options({
    'vagrant_config' => <<ENDCONFIG
config.vm.synced_folder "#{File.join(ENV['PWD'], 'cache')}", '/tmp/cache'
ENDCONFIG
  })
end

However, the resulting Vagrantfile is unusable:

Vagrant.configure('2') do |outer_config|
  outer_config.vm.define "chef-server" do |config|
    config.vm.hostname = "chef-server"
config.vm.synced_folder "/Users/hhh/work/opscode/test/chef-server-test/cache", '/tmp/cache'
  end
end

Can't use Chef::Node::ImmutableMash in "attributes" attribute in the machine resource

For example:

attributes/default.rb:

node["people"]["bob"] = "Bobbert"
node["people"]["stanley"] = "Stanbert"

recipes/example.rb

machine "myserver" do
  attributes node["people"]
end

example.rb will raise the following exception:

Chef::Exceptions::ImmutableAttributeModification: machine[myserver] (example::example line 3) had an error: Chef::Exceptions::ImmutableAttributeModification: Node attributes are read-only when you do not specify which precedence level to set. To set an attribute use code like `node.default["key"] = "value"'

In order to get the code to work you currently need to convert the node["people"] Chef::Node::ImmutableMash to a hash:

recipes/example.rb

machine "myserver" do
  attributes node["people"].to_hash
end

ERROR: undefined method `config_for_url' for ChefMetal:Module

Hi folks, I don't know if this is an issue or is just me not using chef-metal correctly so this is more of a question.

I have the latest chef-metal (0.11.beta.8) and chef-metal-fog (0.5.beta.4) gems.

I'm running it this way:

chef-client -z digitalocean_ubuntu.rb deploy.rb

This is the content of digitalocean_ubuntu.rb file:

require 'chef_metal_fog'

api_key = ENV['DIGITALOCEAN_API_KEY']
client_id = ENV['DIGITALOCEAN_CLIENT_ID']

with_fog_driver :driver => 'DigitalOcean',
  :digitalocean_api_key => api_key,
  :digitalocean_client_id => client_id

with_provisioner_options(
  'bootstrap_options' => {
    image_name: 'Ubuntu 14.04 x64',
    flavor_name: '2GB',
    region_name: 'New York 1',
  }
)

This is the content of deploy.rb:

require 'chef_metal'

machine 'miguel-test03' do
  recipe 'chef-server'
end

When I run chef-client as I explained, I got this error:

[2014-06-03T15:08:46-03:00] WARN: No config file found or specified on command line, using command line options.
[2014-06-03T15:08:46-03:00] WARN: 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:

```
  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true
```

To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:

```
  knife ssl check -c 
```

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

Starting Chef Client, version 11.12.4
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Compiling Cookbooks...

Running handlers:
[2014-06-03T15:08:50-03:00] ERROR: Running exception handlers
Running handlers complete

[2014-06-03T15:08:50-03:00] ERROR: Exception handlers complete
[2014-06-03T15:08:50-03:00] FATAL: Stacktrace dumped to /Users/miguel/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 3.561456 seconds
[2014-06-03T15:08:50-03:00] ERROR: undefined method `config_for_url' for ChefMetal:Module
[2014-06-03T15:08:50-03:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

I obviously set DIGITALOCEAN_API_KEY and DIGITALOCEAN_CLIENT_ID environment variables.

So, I wonder if I'm missing something in my configuration or if there is another issue causing the error undefined method 'config_for_url' for ChefMetal:Module.

Consider using the newer lxc-download template

https://github.com/opscode/chef-metal/blob/lxc/cookbooks/myapp/recipes/lxc_ubuntu.rb#L5

I think an lxc-download line would look like this.

with_provisioner_options 'template' => 'download', 'template_options'=>['-d','ubuntu','-r','precise','-a','amd64']

The newer lxc-download template downloads a compressed tarball of a prebuilt container's rootfs which can save a lot of time and also uses much less storage space in /var/cache/lxc. The resulting container is the same as when using the older lxc-ubuntu template.

You can see what distros are currently supported by lxc-download template here.

https://images.linuxcontainers.org/

I've compared both methods on my laptop (outside of chef-metal) and here are my results.

Older lxc-ubuntu template:
21 minutes to create
296MB in /var/cache/lxc

Newer lxc-download template:
2.5 minutes to create
56MB in /var/cache/lxc

undefined method `synchronize' for nil:NilClass

After upgrading my chef-metal gem to 0.3, I get the following error when calling a machine resource (which worked OK in 0.2.1)

================================================================================
Error executing action `create` on resource 'machine[backend1]'
================================================================================


NoMethodError
-------------
undefined method `synchronize' for nil:NilClass


Resource Declaration:
---------------------
# In /Users/irving/.chef/local-mode-cache/cache/cookbooks/harness/recipes/private_chef_ha.rb

 42:   machine backend do
 43: 
 44:     local_provisioner_options = {
 45:       'vagrant_config' => vagrant_config
 46:     }
 47:     provisioner_options ChefMetal.enclosing_provisioner_options.merge(local_provisioner_options)
 48: 
 49:     # recipe 'private-chef::provision'
 50:     #recipe 'harness::drbd'
 51: 
 52:     action :create
 53:   end
 54: 



Compiled Resource:
------------------
# Declared in /Users/irving/.chef/local-mode-cache/cache/cookbooks/harness/recipes/private_chef_ha.rb:42:in `block in from_file'

machine("backend1") do
  action [:create]
  updated true
  updated_by_last_action true
  retries 0
  retry_delay 2
  chef_server {:chef_server_url=>"http://127.0.0.1:8900", :options=>{}}
  provisioner #<ChefMetal::Provisioner::VagrantProvisioner:0x007f88da7f15b0 @cluster_path="/Users/irving/harness_vms", @unix_convergence_strategy=#<ChefMetal::ConvergenceStrategy::InstallCached:0x007f88da48b5d8 @client_rb_path="/etc/chef/client.rb", @client_pem_path="/etc/chef/client.pem", @chef_version=nil, @prerelease=nil, @package_cache_path="/Users/irving/.chef/package_cache", @package_cache={}, @tmp_dir="/tmp", @download_lock=#<Mutex:0x007f88da652448>>>
  provisioner_options {"vagrant_options"=>{"vm.box"=>"opscode-centos-6.5", "vm.box_url"=>"http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box"}, "vagrant_config"=>"    config.vm.network \"private_network\", ip: \"33.33.33.21\"\n    config.vm.network \"private_network\", ip: \"33.33.34.5\"\n    config.vm.synced_folder \"/oc/EC/Downloads\", '/tmp/cache'\n    config.vm.provider \"virtualbox\" do |v|\n      v.customize [\n        \"modifyvm\", :id,\n        \"--name\", \"backend1\",\n        \"--memory\", \"2048\",\n        \"--cpus\", \"2\",\n        \"--nictype1\", \"virtio\",\n        \"--nictype2\", \"virtio\",\n        \"--natdnshostresolver1\", \"on\",\n        \"--usb\", \"off\",\n        \"--usbehci\", \"off\"\n      ]\n      v.customize ['createhd',\n                  '--filename', \"/Users/irving/harness_vms/backend1/disk2.vmdk\",\n                  '--size', 2 * 1024,\n                  '--format', 'VMDK']\n      v.customize ['storageattach', :id,\n                  '--storagectl', 'IDE Controller',\n                  '--port', 1,\n                  '--device', 0,\n                  '--type', 'hdd',\n                  '--medium', \"/Users/irving/harness_vms/backend1/disk2.vmdk\"]\n    end\n"}
  cookbook_name "harness"
  recipe_name "private_chef_ha"
end

Syntax for specifying flavor/image?

Unless I missed an obvious example (which is very possible), I'm not sure how to specify these options.

machine 'test'
  recipe 'apt'
  provisioner_options(
    :flavor_ref => 2,
    :image_ref => 67,
    :name => 'chef_test'
  )
end

Error:

ArgumentError
-------------
flavor_ref and name are required for this operation

Chef environment on remote machines

Having an issue setting the chef environment on the remote machines.

Running with -E locally doesn't seem to pass this on.

I can see in the machine resource, Chef::Resource::Machine:11, that an instance variable is set to the current environment but then this doesn't seem to be used anywhere

fog_provisioner hardcoded to public_ip_address

There should be an option whether to specify public or private IP address on ChefMetal::Transport::SSH() vs. hardcoding server.public_ip_address as some hosts in the VPC do not have a public interface.

provisioner_options not valid anymore?

Hi,
README.md, Changelog.md and docs/requirements.md still mention a variable 'provider_options'. Meanwhile this seems to be outdated and replaced by 'add_machine_options'/'with_machine_options'/'machine_options'?

Problems with with_chef_server

I'm now trying to associate provisioned nodes with a chef_server. I'm using:

   with_chef_server node['provisioner']['chef_server_url'], {
      :client_name => machine_name,
      :signing_key_filename => Chef::Config[:client_key]
    }

This fails with a 404 after trying to POST to https://my_server_ip/nodes/my_machine_name. The 404 partially makes sense since the node does not exist. However given this is a post, I'd expect it to try and add the node and hopefully send back 200.

I'm gonna dig deeper but if this looks like I am obviously going about this wrong, it would be great to see an example of the right way to do it.

nil machine object raise expection in dry-run

Hi, John

As we discussed, I always get error in dry run

NoMethodError: undefined method `disconnect' for nil:NilClass

Actually, we always assume machine object is created at some point, however we need to deal with dry-run case, like --why-run provided in chef-client , so that no actual machine is created but do verification purpose.

I fixed this in pre-0.10 version by adding a nil check in machine object before call  disconnect().

metal command seems to not use .chef/knife.rb.

The metal cli command doesn't seem to use the configuration info in .chef/knife.rb. Seems to always use chef-zero even if I pass in the chef server url with -S. And it doesn't seem to pick up any other parameters from .chef/knife.rb

Add '--config-file-jail .' to the example given where you first spin up a box.

It would probably save people a lot of hassle if the example of running 'chef-client -z -o myapp::vagrant,myapp::linux,myapp::small' were instead 'chef-client -z --config-file-jail . -o myapp::vagrant,myapp::linux,myapp::small'.

I had an existing ewright.pem file from a working knife-against-a-real-chef-server config in my homedir -- jail'ing the config file reads fixes that and lets a newbie get started without being too confused and reading all the stack traces.

The 'right' fix for me is to fix my knife config, of course, but... that's a different problem.

ec2 availability_zone ignored

I tried setting the variable :availability_zone and or region_id to try and specify the az within the region I have defined. For some reason, it's ignored and or not passed through, even when specified on the compute_options portion.

with_fog_ec2_provisioner :region => "us-west-2"

with_provisioner_options :bootstrap_options => {
:image_id => "ami-xxx",
:flavor_id => "m1.small",
:availability_zone => "us-west-2a"
}

Are there plans to make the fog gem an "opt in"?

I'm actually using fog currently but plan to migrate off of fog and port contributions of my vsphere driver to https://github.com/RallySoftware-cookbooks/chef-metal-vsphere. My primary complaint with fog is its bulk. It is indeed a heavy fog and adds considerable time to building out our Vagrant environments. Once I migrate off of fog, I'd like to not have the bits included in my Chef-Metal gem installs.

I'm new to Rubygems and it may be possible to ignore dependencies but I thought I'd ask here if there are plans to make it a voluntary install.

with_chef_local_server :port gets you two listening chef-zero instances

If you attempt to override the :port like so:

with_chef_local_server :chef_repo_path => repo_path,
    :port => 9010

Then this happens:

[2014-06-04T10:52:10-07:00] INFO: Starting chef-zero on port 8889 with repository at repository at /oc/src/ec-metal-vagrant
  One version per cookbook

[2014-06-04T10:52:10-07:00] INFO: Forking chef instance to converge...
Starting Chef Client, version 11.14.0.alpha.4
[2014-06-04T10:52:10-07:00] INFO: *** Chef 11.14.0.alpha.4 ***
[2014-06-04T10:52:10-07:00] INFO: Chef-client pid: 64782
....snip....
Compiling Cookbooks...
[2014-06-04T10:52:12-07:00] INFO: Starting chef-zero on port 9010 with repository at repository at /oc/src/ec-metal-vagrant
  One version per cookbook
  cookbooks at /oc/src/ec-metal-vagrant/cookbooks, /oc/src/ec-metal-vagrant/vendor/cookbooks

... you get a chef-zero on port 8889 and one on port 9010

dependency chef-metal-vagrant

latest commit changed depency for chef-metal-vagrant from
s.add_dependency 'chef-metal-vagrant', '0.4.beta.2' to
s.add_dependency 'chef-metal-vagrant', '~> 0.4'

It seems bundler does not resolve this as chef-metal-vagrant only has 0.4 beta releases but no stable 0.4 release?

Question: Is there an example for 'with_chef_server'

I see the readme states that I can point at a chef server using with_chef_server. When trying to do this in my vagrant.rb file, I can't seem to make it work. Is there any example syntax for this option?

Here is what I have right now (example is obviously replaced in my code with the real domain name):

with_chef_server "https://chef-server.eng.example.com"

This causes an error (see error below):

JSON::ParserError: Top level JSON object must be a Hash or Array. (actual: NilClass)

SoftLayer provisioning options?

Hello!

I’ve got fog and https://github.com/softlayer/fog-softlayer installed, and it looks like it understands the softlayer fog provider (given the source files the traceback is going through), but it keeps giving me this error whenever I specify a machine, no matter what I put in:

[2014-05-19T14:11:21-07:00] ERROR: machine_batch[default] (mytest::smalltest_cluster line 126) had an error: ArgumentError: name, domain, cpu and ram are required for this operation

It looks like I need to specify sizing (memory/cpu/etc) options somehow there, but I actually can’t see any examples of that happening in myapp or anywhere. How does one configure that stuff with chef-metal? It looks like with_provisioner_options is the right way to do that, but I must be missing something, because nothing I do is making this work. :-)

If it helps, here’s what I am doing:

 : tspencer-work.local $; cat softlayer_provider.rb 
#
# This sets up the softlayer provider
#
require 'fog/softlayer'
require 'chef_metal_fog'

with_fog_provisioner :provider => 'SoftLayer',
    :softlayer_username => ENV['SOFTLAYER_USERNAME'],
    :softlayer_api_key => ENV['SOFTLAYER_API_KEY']

with_provisioner_options :name => 'tspencer-chefmetal-footest',
    :domain => 'foo.com',
    :cpu => 2,
    :ram => 2048,
    :hourlyBillingFlag => false,
    :localDiskFlag => true,
    :os_code => 'CENTOS_6_64'

 : tspencer-work.local $; 

Seems like I shouldn’t have to specify name, because the machine resource should set that for me, but I just threw that in there just to try it out. I've also tried changing the cpu/ram/etc stuff to match other keywords in fog-softlayer, but I keep getting the same error.

Anyways, let me know what I can do to try to figure this out. Thanks again, and have fun!

metal binary complains about private key

working off of the beta.5 bits, if I run:

metal destroy QA1T3NDEVOPSLABCHEF01

I receive this error:

[2014-05-28T13:43:09-07:00] INFO: Starting chef-zero on port 8889 with repository at repository at /home/mwrock/dev/DevOps/chef-repo
  One version per cookbook

{:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"mwrock", :signing_key_filename=>"/home/mwrock/dev/DevOps/chef-repo/.chef/mwrock.pem"}}
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/mixlib-authentication-1.3.0/lib/mixlib/authentication/signedheaderauth.rb:94:in `private_encrypt': private key needed. (OpenSSL::PKey::RSAError)

Note that

{:chef_server_url=>"http://127.0.0.1:8889", :options=>{:client_name=>"mwrock", :signing_key_filename=>"/home/mwrock/dev/DevOps/chef-repo/.chef/mwrock.pem"}}

is output I hacked in to see the server info.

I'm still figuring my way around chef keys but the above key mwrock.pem is a key that is in my knife.rb and configured for an actual chef server. Should a chef-zero run ignore that key?

Thanks!

Error executing action `converge` on resource 'machine_batch[default]'

While attempting to try out chef-metal using the given example found in the chef-metal readme on github, I run into the following error:

Error executing action converge on resource 'machine_batch[default]'

NoMethodError

undefined method `node' for #ChefMetal::AddPrefixActionHandler:0x0000000273cfd8

Resource Declaration:

In /home/justin/.chef/local-mode-cache/cache/cookbooks/myapp/recipes/small.rb

5: machine 'mario' do
6: #recipe 'mydb'
7: tag 'mydb_master'
8: action [:delete, :create]
9: end
10:

I didn't modify the cookbooks/recipes at all and others in our office are running into the same problem when testing chef-metal.

ruby version: 2.1.1 (also tried 1.9.3)
chef version: 11.12.4
operating system: ubuntu 14.04 (tested on OSX mavericks as well)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.