[chef] Re: Re: RE: Re: RE: Re: RE: Re: custom json attributes to powershell variables


Chronological Thread 
  • From: Simon Hawkins < >
  • To: "< >" < >
  • Subject: [chef] Re: Re: RE: Re: RE: Re: RE: Re: custom json attributes to powershell variables
  • Date: Fri, 6 Jun 2014 21:19:08 +0000
  • Accept-language: en-GB, en-US
  • Authentication-results: spf=none (sender IP is ) ;

I know I can do

Netsh ...; restart - which reboots the windows box fine.

So the ; kinda serves as && in bash, but chef seems to hang on to it and doesn't terminate the run.

It seems like as soon as the ip is changed, the chef-run holds on until it eventually times out.

I tried doing 

Netsh; exit 
Netsh; return 

And it still didn't terminate the run.

The other option is to change the ip and only apply on a reboot, but i couldn't see you could do that with netsh or wmi.

I could change the ip in the registry but I think that's not a nice way of doing it.

Cheers,
Simon.



Sent from my iPhone

On 6 Jun 2014, at 21:33, "Kenneth Barry" < "> > wrote:

MAybe your looking to run an asyncronous task, that exits immediately, so that chef can "feel complete"

I know in PowerShell its possible to call an exit, but pass in a command, so it always exits, and the exit code is merely, was I able to call the command or not, doesnt care if the command called fails whatever its doing. The result is, a clean exit. The script might have a sleep for a few seconds, then the ip change?



On Fri, Jun 6, 2014 at 8:33 AM, Simon Hawkins < " target="_blank"> > wrote:

Hi Greg,

 

I managed to get this working which is great, but had to use netsh on my 2008 server because the applets are for 2012 only.

 

When I run the recipe, it works fine, but the problem is, as the IP gets changed immediately, the chef-run hangs because it loses connection (as the IP has changed).

 

Is there any way to force the run to end at that point, e.g, immediately after the netsh command has run or at the same time?

 

Cheers,

Simon.

 

From: Greg Zapp [mailto: " target="_blank"> ]
Sent: 05 June 2014 12:48
To: " target="_blank">
Subject: [chef] Re: RE: Re: RE: Re: custom json attributes to powershell variables

 

Ohai collects system information and stores it into the node mash(node['whatever']) when Chef starts. When a Chef run completes it does a node.save which stores all the node information in Chef server.

 

I believe in this case you would want to reload Ohai to ensure that by the end of the first run the new IP is saved out.  If you search for "Reload Ohai" here you will see an example: http://docs.opscode.com/ohai.html .  I would recommend using a "notifies" like in the examples.

 

If this recipe is used on every subsequent Chef run it may be worth looking into preventing the powershell script and notification from running when it doesn't need to.

 

-Greg

 

On Thu, Jun 5, 2014 at 11:31 PM, Simon Hawkins < " target="_blank"> > wrote:

Cool that works. J

 

Silly question but after this has run, is there an automated way to update the node information “knife node edit node2 –a” so it has the new IP info?

 

Does something like Ohai send the info back automatically and update the config?

 

Cheers,

Simon.

 

From: Greg Zapp [mailto: " target="_blank"> ]
Sent: 05 June 2014 12:17
To: " target="_blank">
Subject: [chef] Re: RE: Re: custom json attributes to powershell variables

 

Hi Simon,

 

Sorry about that! :|  "ip_address" is a string(at least I'm not sure if you can look it up with a symbol) and should to be in quotes: #{node['ip_address']}

 

 

-Greg

 

On Thu, Jun 5, 2014 at 10:29 PM, Simon Hawkins < " target="_blank"> > wrote:

Hi Greg,

 

I get the following output:

 

10.x.x.x [2014-06-05T11:24:50+01:00] ERROR: Running exception handlers

10.x.x.x [2014-06-05T11:24:50+01:00] ERROR: Exception handlers complete

10.x.x.x [2014-06-05T11:24:50+01:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out

10.x.x.x [2014-06-05T11:24:50+01:00] FATAL: NoMethodError: undefined method `ip_address' for Chef::Resource::PowershellScript

 

New-NetIPAddress –InterfaceAlias "Local Area Connection" –IPv4Address #{node[ip_address]}

 

Does it have to be in quotes? “#{node[ip_address]}”

 

Cheers,

Simon.

 

From: Greg Zapp [mailto: " target="_blank"> ]
Sent: 04 June 2014 14:59
To: " target="_blank">
Subject: [chef] Re: custom json attributes to powershell variables

 

Hi Simon,

 

I have updated that gist to show two examples.  The second block there will run the action immediately.  You might need that if the rest of your Chef run requires the IP address being changed to what you've passed in.

 

-Greg

 

On Thu, Jun 5, 2014 at 1:44 AM, Greg Zapp < " target="_blank"> > wrote:

Hi Simon,

 

-j would be correct but it takes a JSON string: '{ "ip_address" : "10.x.x.x", "prefix" : 24, "gateway" : "10.x.x.x" }'

 

After that, assuming you have knife bootstrap working with Windows, you should be able to use string interpolation inside a HEREDOC to craft your powershell command/script with the attributes: https://gist.github.com/ProTip/a2301025cfc4d8b9500f

 

Cheers,

   -Greg

 

On Thu, Jun 5, 2014 at 1:20 AM, Greg Zapp < " target="_blank"> > wrote:

Hi Simon,

 

Is your difficulty with getting the attributes into Chef or using them once they are there?

 

-Greg

 

On Wed, Jun 4, 2014 at 9:36 PM, < " target="_blank"> > wrote:

Hi,

Do you know how I would be able to save JSON custom attributes to a powershell
variable in a recipe?

When I bootstrap a Windows machine I would like to pass the IP, Subnet, GW and
DNS Servers into custom attributes and when the recipe is applied, the windows
machine sets the correct information to the network card (using powershell).

Since knife vsphere doesn't currently support vmware windows customisations I
can't think of another way.

So I would end up with something like this in the recipe (which is a powershell
script):

$ipAddress = customIPAttribute
$gateway = customGWAttribute
etc, within the recipe.

Cheers,
Simon.

 

 

 


Disclaimer

This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Holden House, 57 Rathbone Place, London, W1T 1JU, UK Registered in England and Wales under company no. 4269861


 

 



Disclaimer

This message is intended only for the use of the person(s) ("Intended Recipient") to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Holden House, 57 Rathbone Place, London, W1T 1JU, UK Registered in England and Wales under company no. 4269861





Archive powered by MHonArc 2.6.16.

§