Retrieve values from resources

I’m working on a cookbook with a template that has some conditional logic driven by the version of mysql. A recipe installs mysql and then renders a file from the template. There used to be a “default_version_for” function that would provide the default version of mysql to install on a given OS, but this function has been removed, presumably because if the version is not specified, the default version for the OS is automatically installed. However, now that the function is gone, I’m wondering how to obtain the version of mysql that was installed when no version is specified. I tried getting the resource via:

server_resource = resources(mysql_service: node[‘mysql’][‘service_name’])

and then accessing the version using:

server_resource.version

However, that returns nil. How can instance-variable values be retrieved from resources?

Thanks,

John

r = mysql_resource 'default'
r.parsed_version

-s

On Thu, Sep 4, 2014 at 4:58 PM, John Warren j0hnwarr3n@gmail.com wrote:

I’m working on a cookbook with a template that has some conditional logic
driven by the version of mysql. A recipe installs mysql and then renders a
file from the template. There used to be a “default_version_for” function
that would provide the default version of mysql to install on a given OS,
but this function has been removed, presumably because if the version is not
specified, the default version for the OS is automatically installed.
However, now that the function is gone, I’m wondering how to obtain the
version of mysql that was installed when no version is specified. I tried
getting the resource via:

server_resource = resources(mysql_service: node['mysql']['service_name'])

and then accessing the version using:

server_resource.version

However, that returns nil. How can instance-variable values be retrieved
from resources?

Thanks,

John

er .....

r = mysql_service 'default'
r.parsed_version

On Thu, Sep 4, 2014 at 5:11 PM, Sean OMeara someara@opscode.com wrote:

r = mysql_resource 'default'
r.parsed_version

-s

On Thu, Sep 4, 2014 at 4:58 PM, John Warren j0hnwarr3n@gmail.com wrote:

I’m working on a cookbook with a template that has some conditional logic
driven by the version of mysql. A recipe installs mysql and then renders a
file from the template. There used to be a “default_version_for” function
that would provide the default version of mysql to install on a given OS,
but this function has been removed, presumably because if the version is not
specified, the default version for the OS is automatically installed.
However, now that the function is gone, I’m wondering how to obtain the
version of mysql that was installed when no version is specified. I tried
getting the resource via:

server_resource = resources(mysql_service: node['mysql']['service_name'])

and then accessing the version using:

server_resource.version

However, that returns nil. How can instance-variable values be retrieved
from resources?

Thanks,

John

Alternatively, you could look into the resource collection and call
the method.. which is how ChefSpec works

https://github.com/opscode-cookbooks/mysql/blob/master/spec/unit/mysql_server/rhel/6/default_spec.rb#L16

-s

On Thu, Sep 4, 2014 at 5:12 PM, Sean OMeara someara@opscode.com wrote:

er .....

r = mysql_service 'default'
r.parsed_version

On Thu, Sep 4, 2014 at 5:11 PM, Sean OMeara someara@opscode.com wrote:

r = mysql_resource 'default'
r.parsed_version

-s

On Thu, Sep 4, 2014 at 4:58 PM, John Warren j0hnwarr3n@gmail.com wrote:

I’m working on a cookbook with a template that has some conditional logic
driven by the version of mysql. A recipe installs mysql and then renders a
file from the template. There used to be a “default_version_for” function
that would provide the default version of mysql to install on a given OS,
but this function has been removed, presumably because if the version is not
specified, the default version for the OS is automatically installed.
However, now that the function is gone, I’m wondering how to obtain the
version of mysql that was installed when no version is specified. I tried
getting the resource via:

server_resource = resources(mysql_service: node['mysql']['service_name'])

and then accessing the version using:

server_resource.version

However, that returns nil. How can instance-variable values be retrieved
from resources?

Thanks,

John