Retrieving Ohai Windows system information

Good Afternoon Guys,
I’m pretty new to Chef but have been trialling it for a few weeks. I’m running into trouble with Ohai.
I’m trying to obtain disk size for a windows node (C drive) and free space for a D: and E:
I’m getting the below error, I’m sure it’s related to the way I’m calling the node info but I’m not au fait enough with chef yet to know.
Code:
cdskfr = node[:filesystem][c:][‘kb_size’]
ddskfr = node[:filesystem][d:][‘kb_available’]
edskfr = node[:filesystem][e:][‘kb_available’]

and the error I get is:
[2014-05-09T12:41:50-04:00] FATAL: 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”’

I’ve spent a lot of time googling this and can find plenty of info on how to create custom plugins, but no info on how to retrieve info that is clear. This is not a custom plugin that I have written, just the usual ones bundled with Chef.
I can retrieve a hostname with Ohai with no problem.
Any useful comments/pointers greatly appreciated.

Thanks
Chris

That needs to be node['filesystem']['c:']['kb_size']. You accidentally used the syntax for a slice.

--Noah

On May 9, 2014, at 10:02 AM, "ChristopherHall@air-watch.com" ChristopherHall@air-watch.com wrote:

Good Afternoon Guys,
I’m pretty new to Chef but have been trialling it for a few weeks. I’m running into trouble with Ohai.
I’m trying to obtain disk size for a windows node (C drive) and free space for a D: and E:
I’m getting the below error, I’m sure it’s related to the way I’m calling the node info but I’m not au fait enough with chef yet to know.
Code:
cdskfr = node[:filesystem][c:]['kb_size']
ddskfr = node[:filesystem][d:]['kb_available']
edskfr = node[:filesystem][e:]['kb_available']

and the error I get is:
[2014-05-09T12:41:50-04:00] FATAL: 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"'

I’ve spent a lot of time googling this and can find plenty of info on how to create custom plugins, but no info on how to retrieve info that is clear. This is not a custom plugin that I have written, just the usual ones bundled with Chef.
I can retrieve a hostname with Ohai with no problem.
Any useful comments/pointers greatly appreciated.

Thanks
Chris

Thanks for that Noah,
I've changed the code as you suggested but I'm getting errors around 'No method defined'.
I've got the Ohai cookbook included and I can grab the hostname and roles from the node with no problems.
The code I'm using is below and the error after that:
$cdskfr = node['filesystem']['c:']['kb_size']

Nodename [2014-05-12T05:00:23-04:00] FATAL: NoMethodError: undefined method `' for nil:NilClass

AS I understand it, filesystem is a plugin, not a built in function, so I wonder if I'm missing something with regard to loading the plugin?

Thanks
Chris

-----Original Message-----
From: Noah Kantrowitz [mailto:noah@coderanger.net]
Sent: 09 May 2014 18:06
To: chef@lists.opscode.com
Subject: [chef] Re: Retrieving Ohai Windows system information

That needs to be node['filesystem']['c:']['kb_size']. You accidentally used the syntax for a slice.

--Noah

On May 9, 2014, at 10:02 AM, "ChristopherHall@air-watch.com" ChristopherHall@air-watch.com wrote:

Good Afternoon Guys,
I'm pretty new to Chef but have been trialling it for a few weeks. I'm running into trouble with Ohai.
I'm trying to obtain disk size for a windows node (C drive) and free space for a D: and E:
I'm getting the below error, I'm sure it's related to the way I'm calling the node info but I'm not au fait enough with chef yet to know.
Code:
cdskfr = node[:filesystem][c:]['kb_size'] ddskfr =
node[:filesystem][d:]['kb_available']
edskfr = node[:filesystem][e:]['kb_available']

and the error I get is:
[2014-05-09T12:41:50-04:00] FATAL: 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"'

I've spent a lot of time googling this and can find plenty of info on how to create custom plugins, but no info on how to retrieve info that is clear. This is not a custom plugin that I have written, just the usual ones bundled with Chef.
I can retrieve a hostname with Ohai with no problem.
Any useful comments/pointers greatly appreciated.

Thanks
Chris

IIRC attribute are case sensitive, windows drive letter are uppercase.

$cdskfr = node['filesystem']['C:']['kb_size'] should work

Le 2014-05-12 11:05, ChristopherHall@air-watch.com a écrit :

Thanks for that Noah,
I've changed the code as you suggested but I'm getting errors around 'No method defined'.
I've got the Ohai cookbook included and I can grab the hostname and roles from the node with no problems.
The code I'm using is below and the error after that:
$cdskfr = node['filesystem']['c:']['kb_size']

Nodename [2014-05-12T05:00:23-04:00] FATAL: NoMethodError: undefined method `' for nil:NilClass

AS I understand it, filesystem is a plugin, not a built in function, so I wonder if I'm missing something with regard to loading the plugin?

Thanks
Chris

-----Original Message-----
From: Noah Kantrowitz [mailto:noah@coderanger.net]
Sent: 09 May 2014 18:06
To: chef@lists.opscode.com
Subject: [chef] Re: Retrieving Ohai Windows system information

That needs to be node['filesystem']['c:']['kb_size']. You accidentally used the syntax for a slice.

--Noah

On May 9, 2014, at 10:02 AM, "ChristopherHall@air-watch.com" ChristopherHall@air-watch.com wrote:

Good Afternoon Guys, I'm pretty new to Chef but have been trialling it for a few weeks. I'm running into trouble with Ohai. I'm trying to obtain disk size for a windows node (C drive) and free space for a D: and E: I'm getting the below error, I'm sure it's related to the way I'm calling the node info but I'm not au fait enough with chef yet to know. Code: cdskfr = node[:filesystem][c:]['kb_size'] ddskfr = node[:filesystem][d:]['kb_available'] edskfr = node[:filesystem][e:]['kb_available'] and the error I get is: [2014-05-09T12:41:50-04:00] FATAL: 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"' I've spent a lot of time googling this and can find plenty of info on how to create custom plugins, but no info on how to retrieve info that is clear. This is not a custom plugin that I have written, just the usual ones bundled
with Chef. I can retrieve a hostname with Ohai with no problem. Any useful comments/pointers greatly appreciated. Thanks Chris

Thanks very much, it was the case sensitivity :slight_smile:

From: Tensibai [mailto:tensibai@iabis.net]
Sent: 12 May 2014 10:50
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: Retrieving Ohai Windows system information

IIRC attribute are case sensitive, windows drive letter are uppercase.

$cdskfr = node[‘filesystem’][‘C:’][‘kb_size’] should work

Le 2014-05-12 11:05, ChristopherHall@air-watch.commailto:ChristopherHall@air-watch.com a écrit :

Thanks for that Noah,

I’ve changed the code as you suggested but I’m getting errors around ‘No method defined’.

I’ve got the Ohai cookbook included and I can grab the hostname and roles from the node with no problems.

The code I’m using is below and the error after that:

$cdskfr = node[‘filesystem’][‘c:’][‘kb_size’]

Nodename [2014-05-12T05:00:23-04:00] FATAL: NoMethodError: undefined method `[]’ for nil:NilClass

AS I understand it, filesystem is a plugin, not a built in function, so I wonder if I’m missing something with regard to loading the plugin?

Thanks

Chris

-----Original Message-----

From: Noah Kantrowitz [mailto:noah@coderanger.netmailto:noah@coderanger.net]

Sent: 09 May 2014 18:06

To: chef@lists.opscode.commailto:chef@lists.opscode.com

Subject: [chef] Re: Retrieving Ohai Windows system information

That needs to be node[‘filesystem’][‘c:’][‘kb_size’]. You accidentally used the syntax for a slice.

–Noah

On May 9, 2014, at 10:02 AM, "ChristopherHall@air-watch.commailto:ChristopherHall@air-watch.com" <ChristopherHall@air-watch.commailto:ChristopherHall@air-watch.com> wrote:
Good Afternoon Guys, I’m pretty new to Chef but have been trialling it for a few weeks. I’m running into trouble with Ohai. I’m trying to obtain disk size for a windows node (C drive) and free space for a D: and E: I’m getting the below error, I’m sure it’s related to the way I’m calling the node info but I’m not au fait enough with chef yet to know. Code: cdskfr = node[:filesystem][c:][‘kb_size’] ddskfr = node[:filesystem][d:][‘kb_available’] edskfr = node[:filesystem][e:][‘kb_available’] and the error I get is: [2014-05-09T12:41:50-04:00] FATAL: 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”’ I’ve spent a lot of time googling this and can find plenty of info on how to create custom plugins, but no info on how to retrieve info that is clear. This is not a custom plugin that I have written, just the usual ones bundled with Chef. I can retrieve a hostname with Ohai with no problem. Any useful comments/pointers greatly appreciated. Thanks Chris