Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

chef provision -d option does not work as expected #618

Closed
alainchiasson opened this issue Dec 4, 2015 · 6 comments
Closed

chef provision -d option does not work as expected #618

alainchiasson opened this issue Dec 4, 2015 · 6 comments
Labels
Aspect: Documentation How do we use this project? Triage: Duplicate Indicates an issue is a duplicate of other open issue.

Comments

@alainchiasson
Copy link

I have this problem both with vagrant and vsphere.

I have the following machine definition in provision\recipes\sparkler_create.rb :

machine 'sparkler' do
  recipe 'apt::default'
end

When running it as :

chef provision --no-policy --recipe sparkler_create

All goes well - the machine is created in VSpere as expected. From the documentation, I expect to be able to run :

chef provision --d --no-policy --recipe sparkler_create

And have it get destroyed and yet it does not and reruns action :install.

± |test_provision ?:2 ✗| → chef provision -d --no-policy --recipe sparkler_create
[2015-12-04T09:31:48-05:00] WARN: found a directory test in the cookbook path, but it contains no cookbook files. skipping.
Compiling Cookbooks...
Recipe: provision::vsphere
  * chef_gem[chef-provisioning-vsphere] action install (up to date)
  * chef_gem[chef-provisioning-vsphere] action installWARN: Unresolved specs during Gem::Specification.reset:
      mini_portile (~> 0.6.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
 (up to date)
Recipe: provision::sparkler_create
  * machine[sparkler] action converge[2015-12-04T09:31:52-05:00] WARN: Checking to see if {"driver_url"=>"vsphere://xxxxxxxxxxx/sdk?use_ssl=true&insecure=true", "driver_version"=>"0.8.2", "server_id"=>"xxxxxxxxxxxxxxx", "is_windows"=>false, "allocated_at"=>"2015-12-04 14:03:07 UTC", "ipaddress"=>"172.17.80.21"} has been created...
establishing connection to xxxxxxxxxxxxxxxxx
[2015-12-04T09:31:53-05:00] WARN: returning existing machine
...

All works well if I add the action :destroy in the cookbook (I actually have a sparkler_destroy )

± |test_provision ?:2 ✗| → chef provision -d --no-policy --recipe sparkler_destroy
[2015-12-04T09:39:52-05:00] WARN: found a directory test in the cookbook path, but it contains no cookbook files. skipping.
Compiling Cookbooks...
Recipe: provision::vsphere
  * chef_gem[chef-provisioning-vsphere] action install (up to date)
  * chef_gem[chef-provisioning-vsphere] action installWARN: Unresolved specs during Gem::Specification.reset:
      mini_portile (~> 0.6.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
 (up to date)
Recipe: provision::sparkler_destroy
  * machine[sparkler] action destroyestablishing connection to XXXXX

    - Delete VM [RateReview/sparkler]
    - delete node sparkler at https://XXXXXX/organizations/devops
    - delete client sparkler at clients
@alainchiasson
Copy link
Author

Thought I would also add :

○ → chef --version
Chef Development Kit Version: 0.10.0
chef-client version: 12.5.1
berks version: 4.0.1
kitchen version: 1.4.2

@danielsdeleo
Copy link
Contributor

chef provision relies on you passing options from its context object to your actual recipe. You need to do something like:

# The context holds the values you passed in on the command line
context = ChefDK::ProvisioningData.context

machine 'sparkler' do
  recipe 'apt::default'
  action(context.action)
end

What documentation are you following?

@alainchiasson
Copy link
Author

I'm looking at the documentation for "chef provision" : https://docs.chef.io/ctl_chef.html#chef-provision There is a NOTE: that mentions context but I was not using the option.

I tried what you mention and everything works - which is great !! Thanks you !!

But also begs the question - What documentation are you following ? My background is Ops and Bash. I still get lost in ruby and objects. I did try going through the chef-dk code.

And MANY Thanks for the quick response !!

@danielsdeleo
Copy link
Contributor

I wrote chef provision but I sometimes forget the details of everything. I included an example that uses most features of chef provision in this blog post: https://www.chef.io/blog/2015/08/18/policyfiles-a-guided-tour/ so that's what I look at when I need a reminder.

context = ChefDK::ProvisioningData.context

# Set the port dynamically via the command line:
target_port = context.opts.port

with_driver 'vagrant:~/.vagrant.d/boxes' do

  options = {
    vagrant_options: {
      'vm.box' => 'opscode-ubuntu-14.04',
      'vm.network' => ":forwarded_port, guest: 80, host: #{target_port}"
    },
    convergence_options: context.convergence_options
  }


  machine context.node_name do
    machine_options(options)

    # This forces a chef run every time, which is sensible for `chef provision`
    # use cases.
    converge(true)
    action(context.action)
  end
end

Anyway, I'll notify the documentation team about this and see if I can get an improved example included on the page you linked.

@danielsdeleo
Copy link
Contributor

I've filed this bug in the chef-docs issues, so I am closing this one.

chef/chef-web-docs#768

@alainchiasson
Copy link
Author

I have been ignoring policyfiles for now - and this is probably why I missed the above blog entry (or glanced over it quickly).

No time like the present though !! Thanks again.

@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
@tas50 tas50 added Aspect: Documentation How do we use this project? Triage: Duplicate Indicates an issue is a duplicate of other open issue. and removed Type: Documentation labels Jan 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Aspect: Documentation How do we use this project? Triage: Duplicate Indicates an issue is a duplicate of other open issue.
Development

No branches or pull requests

5 participants