Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting up vsphere driver once and calling it from different recipes #86

Open
bhaliti opened this issue Aug 30, 2016 · 20 comments
Open

Comments

@bhaliti
Copy link

bhaliti commented Aug 30, 2016

Hi,

I am trying to deploy a server from chef-provisioning-vsphere using the example:

now I am trying to use the resource batch to build multiple vms at once and am having a hard time understanding how to set it up.

here is an example:

machine_batch do
action :setup
machines 'a', 'b', 'c', 'd', 'e',
recipe['chef-client::service']
end

I am using a template which has the chef-client installed and the client.rb file and cert and validator.pem

I want my new vms to have a: new IP, gateway, dns and join the domain.

After that is setup I want to run the chef-client cookbook to create the chef-client as a service to check in every so often and remove the validator.pem (that's part of the cookbook and should work as expected)

the recipes that I am struggling with are

example: Vcenter.rb

with_machine_options :bootstrap_options => {
use_linked_clone: true,
num_cpus: 2,
memory_mb: 4096,
network_name: ['vlan_20_172.21.20'],
datacenter: 'datacenter_name',
resource_pool: 'cluster',
template_name: 'path to template',
customization_spec: {
ipsettings: {
dnsServerList: ['1.2.3.31','1.2.3.41']
},
domain: 'blah.com',
domainAdmin: '[email protected]',
domainAdminPassword: 'Passwordyoyoyo',
org_name: 'acme',
product_id: 'CDAA-SSSC-3455-FF77-2AAC',
win_time_zone: 4
}
ssh: {
user: 'administrator',
password: 'password',
paranoid: false,
}
}

and the recipe that I want to use to build the new vms

newVMs.rb
machine_batch do
action :setup
machines 'a', 'b', 'c', 'd', 'e',
recipe['chef-client::service']
end

How can I use the newVMs.rb recipe without having all of the info that's on Vcenter.rb file. Instead reference to it somehow??? Tried include_recipe 'vms::VCenter'
i am getting this error:
Error executing action converge on resource 'machine[DS-TEST01]'
================================================================================

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

the recipe that I want to use to build new vms, I want it to be clean all the machine_options and customization_specs I'd like to keep on a different file. this is for a windows environment by the way.

any help would be greatly appreciated.

thanks

@mwrock
Copy link
Contributor

mwrock commented Sep 15, 2016

I'd recommend adding your common config settings to a hash. Then for each machine merge the config settings specific to that machine with your common settings into a new variable. Then pass that variable to the machine resource's machine_options property.

@bhaliti
Copy link
Author

bhaliti commented Sep 20, 2016

speak English man

@mwrock
Copy link
Contributor

mwrock commented Sep 21, 2016

I am very sorry. Let me try to be more clear.

First I would create a variable to store your common options in a hash:

opts =  {
    bootstrap_options:  {
      use_linked_clone:  true,
      datacenter:  'DC2',
      ssh:  {
        user:  'administrator',
        password:  'pass',
        port:  5985
      },
      customization_spec:  {
        ipsettings:  {
          subnetMask:  '255.255.252.0',
          gateway:  ['11.11.1.1'],
          dnsServerList:  ['8.8.8.8', '8.8.4.4']
        },
        domain:  'local',
        org_name:  'org',
        product_id:  '',
        win_time_zone:  4
      }
    }
  }

Now inside your machine_batch resource yo can reuse these options:

machine_batch my_batch do
  1.upto(3) do |i|
    machine_opts = opts.dup
    machine_opts[:bootstrap_options][:customization_spec][:ip] = "1.1.1.#{i}"
    machine "web#{i}" do
      machine_options machine_opts
    end
  end
end

Hope that makes more sense

@bhaliti
Copy link
Author

bhaliti commented Sep 21, 2016

1.upto(3) do |i| (so this will be used for up to 3 times?)
machine_opts = opts.dup (opts.dup??? not sure what that is)
machine "web#{i}" do (web#{i} - will it assume web01, web02, web03, or do I have to change the hash to what I need it to be????)

@bhaliti
Copy link
Author

bhaliti commented Sep 22, 2016

here is what I got when I ran that above. all in the same file though? I am not sure if that is the way I am supposed to do it
ERROR: No resource, method, or local variable named my_batch' forChef::Recipe

@mwrock
Copy link
Contributor

mwrock commented Sep 22, 2016

sorry. my_batch should be in quotes. To answer your other questions:

  • 1.upto(3) is ruby for saying "1 to 3".
  • dup "clones" the hash. You want this because otherwise each machine will be operating on the same hash instance but you want each machine to be different.
  • machine "web#{i}" will create machines named web1, web2, and web3.

Hope that helps.

@bhaliti
Copy link
Author

bhaliti commented Sep 22, 2016

okay. cool thanks.
what about for the ip 1.1.1.# If i want it to start from 65 and use .66, .67, .68 is there a way to do that?

@bhaliti
Copy link
Author

bhaliti commented Sep 22, 2016

WARN WinRM::WinRMWebService : WinRM::WinRMWebService#run_powershell_script is deprecated. Use WinRM::CommandExecutor#run_powershell_script instead

@bhaliti
Copy link
Author

bhaliti commented Sep 22, 2016

I am having issues with the IP address, it keeps selecting the same one for
both servers and then both fail,

theoretically machine_opts[:bootstrap_options][:customization_spec][:ip] =
"1.1.1.#{i}" this should pick 1, 2, 3 but it's selecting 1 for both of
them

thanks

On Thu, Sep 22, 2016 at 12:11 PM, Matt Wrock [email protected]
wrote:

sorry. my_batch should be in quotes. To answer your other questions:

  • 1.upto(3) is ruby for saying "1 to 3".
  • dup "clones" the hash. You want this because otherwise each machine
    will be operating on the same hash instance but you want each machine to be
    different.
  • machine "web#{i}" will create machines named web1, web2, and web3.

Hope that helps.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#86 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASyNbZDwX7sVvE9hMunwFPIJP1EorRU9ks5qsratgaJpZM4Jw4qB
.

@mwrock
Copy link
Contributor

mwrock commented Sep 23, 2016

Try:

    opts[:bootstrap_options][:customization_spec][:ip] = "1.1.1.#{i}"
    machine "web#{i}" do
      machine_options opts.dup
    end

This clones the hash as it is sent to the machine instead of using the same variable in each iteration.

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

machine_batch "web" do
1.upto(2) do |i|
opts[:bootstrap_options][:customization_spec][:ip] = "10.x.x.7#{i}"
machine "VV-WEB9#{i}" do
machine_opts = opts.dup
end
end
end


it's assigning the same IP to both of them and then fails on both
image

@mwrock
Copy link
Contributor

mwrock commented Sep 23, 2016

machine "VV-WEB9#{i}" do
machine_opts = opts.dup
end

should be

machine "VV-WEB9#{i}" do
  machine_options opts.dup
end

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

yeah that was from an earlier, I cought that mistake a while back but this is what I am using and still getting that error (minus the hash tag)

#machine_batch "web" do
1.upto(2) do |i|
opts[:bootstrap_options][:customization_spec][:ip] = "10.117.100.7#{i}"
machine "DP-WEB9#{i}" do
machine_options opts.dup
end
end
end

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

is it possible to do this? to avoid that

machine "DP-WEB83" do
opts[:bootstrap_options][:customization_spec][:ip] = "10.117.100.74"
machine_options opts.dup
end
machine "DP-WEB84" do
opts[:bootstrap_options][:customization_spec][:ip] = "10.117.100.75"
machine_options opts.dup
end

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

I realize that it will go much slower but until I can figure out why its not working

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

sorry to keep bugging you, did you have a chance to look at that last email
I sent?

On Fri, Sep 23, 2016 at 10:47 AM, Matt Wrock [email protected]
wrote:

machine "VV-WEB9#{i}" do
machine_opts = opts.dup
end

should be

machine "VV-WEB9#{i}" do
machine_options opts.dup
end


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#86 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASyNbYEvRkj6wMRwWNbAou9tZPVIA4KKks5qs_SLgaJpZM4Jw4qB
.

@mwrock
Copy link
Contributor

mwrock commented Sep 23, 2016

sorry its been hectic on my end. I eventually actually want to test a machine_batch but yes. serializing the machines and not using a batch should get you past that.

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

I tried using

machine "DP-WEB83" do
opts[:bootstrap_options][:customization_spec][:ip] = "10.117.100.74"
machine_options opts.dup
end
machine "DP-WEB84" do
opts[:bootstrap_options][:customization_spec][:ip] = "10.117.100.75"
machine_options opts.dup
end

but it would only build one server, failed to customize the IP and then it
would fail, never get to the second server

On Fri, Sep 23, 2016 at 2:30 PM, Matt Wrock [email protected]
wrote:

sorry its been hectic on my end. I eventually actually want to test a
machine_batch but yes. serializing the machines and not using a batch
should get you past that.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#86 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASyNbf7pFWygdIm4JoR6MBWX95BJsRtkks5qtCjXgaJpZM4Jw4qB
.

@bhaliti
Copy link
Author

bhaliti commented Sep 23, 2016

.

On Tue, Sep 20, 2016 at 8:19 PM, Matt Wrock [email protected]
wrote:

I am very sorry. Let me try to be more clear.

First I would create a variable to store your common options in a hash:

opts = {
bootstrap_options: {
use_linked_clone: true,
datacenter: 'DC2',
ssh: {
user: 'administrator',
password: 'pass',
port: 5985
},
customization_spec: {
ipsettings: {
subnetMask: '255.255.252.0',
gateway: ['11.11.1.1'],
dnsServerList: ['8.8.8.8', '8.8.4.4']
},
domain: 'local',
org_name: 'org',
product_id: '',
win_time_zone: 4
}
}
}

Now inside your machine_batch resource yo can reuse these options:

machine_batch my_batch do
1.upto(3) do |i|
machine_opts = opts.dup
machine_opts[:bootstrap_options][:customization_spec][:ip] = "1.1.1.#{i}"
machine "web#{i}" do
machine_options machine_opts
end
end
end

Hope that makes more sense


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#86 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASyNbeGXoAXBpwh3nDNQ_b6N9gIq6eA4ks5qsIYYgaJpZM4Jw4qB
.

@bhaliti
Copy link
Author

bhaliti commented Oct 11, 2016

HELLOOOO
anybody there?

jjlimepoint pushed a commit to jjlimepoint/chef-provisioning-vsphere that referenced this issue Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants