How to change the name of an attribute with an attribute?


#1

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set
of repos based on the platform version and the environment that the
server is in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] =
“http://repo_centos5_dev…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_dev…”

In a recipe, I have tried variations of the following:

If server is prod…

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev…

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be
more of how chef is handling the attributesd in the Compile Resource
Collection phase of a chef run…

I have different repos for each of my environments (dev, test, prod, QA,
stage1, personal) and different versions of centos for each of these.
Each points to a specific internal url.

Anyone have any ideas?


#2

node.foo.bar.send(“some_crazy_#{attribute_helper}_#{node[“bong”]}”)

–AJ

On 3 February 2012 10:08, Van Fossan,Randy vanfossr@oclc.org wrote:

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set of
repos based on the platform version and the environment that the server is
in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] = “http://repo_centos5_dev…”

default[:repo][:my_centos][:updates_prd_6x] = “http://repo_centos6_dev…”

In a recipe, I have tried variations of the following:

If server is prod….

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev….

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be more
of how chef is handling the attributesd in the Compile Resource Collection
phase of a chef run…

I have different repos for each of my environments (dev, test, prod, QA,
stage1, personal) and different versions of centos for each of these. Each
points to a specific internal url.

Anyone have any ideas?


#3

AJ,

Sorry, I am still just a newbie, I did not follow that…

-----Original Message-----
From: AJ Christensen [mailto:aj@junglist.gen.nz]
Sent: Thursday, February 02, 2012 4:10 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How to change the name of an attribute with an attribute?

node.foo.bar.send(“some_crazy_#{attribute_helper}_#{node[“bong”]}”)

–AJ

On 3 February 2012 10:08, Van Fossan,Randy vanfossr@oclc.org wrote:

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set
of repos based on the platform version and the environment that the
server is in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] = “http://repo_centos5_dev…”

default[:repo][:my_centos][:updates_prd_6x] = “http://repo_centos6_dev…”

In a recipe, I have tried variations of the following:

If server is prod….

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev….

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be
more of how chef is handling the attributesd in the Compile Resource
Collection phase of a chef run…

I have different repos for each of my environments (dev, test, prod,
QA, stage1, personal) and different versions of centos for each of
these. Each points to a specific internal url.

Anyone have any ideas?


#4

AJ meant that you can use Hash syntax or regular ruby method syntax.

node[:foo][:bar] is the same as node.foo.bar

–max

On Thu, Feb 2, 2012 at 1:23 PM, Van Fossan,Randy vanfossr@oclc.org wrote:

AJ,

Sorry, I am still just a newbie, I did not follow that…

-----Original Message-----
From: AJ Christensen [mailto:aj@junglist.gen.nz]
Sent: Thursday, February 02, 2012 4:10 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How to change the name of an attribute with an
attribute?

node.foo.bar.send(“some_crazy_#{attribute_helper}_#{node[“bong”]}”)

–AJ

On 3 February 2012 10:08, Van Fossan,Randy vanfossr@oclc.org wrote:

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set
of repos based on the platform version and the environment that the
server is in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] = “http://repo_centos5_dev.
…”

default[:repo][:my_centos][:updates_prd_6x] = “http://repo_centos6_dev.
…”

In a recipe, I have tried variations of the following:

If server is prod….

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev….

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be
more of how chef is handling the attributesd in the Compile Resource
Collection phase of a chef run…

I have different repos for each of my environments (dev, test, prod,
QA, stage1, personal) and different versions of centos for each of
these. Each points to a specific internal url.

Anyone have any ideas?


#5

another way is

prod_key = :"updates_prd_#{node[:platform_version].to_i}x"
dev_key = :“updates_dev_#{node[:platform_version].to_i}x”

Update_Repo = node[:repo][:my_centos][key_prod]
or
Update_Repo = node[:repo][:my_centos][key_dev]

–max

On Thu, Feb 2, 2012 at 1:26 PM, Max Gorbul max@gorbul.net wrote:

AJ meant that you can use Hash syntax or regular ruby method syntax.

node[:foo][:bar] is the same as node.foo.bar

–max

On Thu, Feb 2, 2012 at 1:23 PM, Van Fossan,Randy vanfossr@oclc.orgwrote:

AJ,

Sorry, I am still just a newbie, I did not follow that…

-----Original Message-----
From: AJ Christensen [mailto:aj@junglist.gen.nz]
Sent: Thursday, February 02, 2012 4:10 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How to change the name of an attribute with an
attribute?

node.foo.bar.send(“some_crazy_#{attribute_helper}_#{node[“bong”]}”)

–AJ

On 3 February 2012 10:08, Van Fossan,Randy vanfossr@oclc.org wrote:

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set
of repos based on the platform version and the environment that the
server is in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] = “http://repo_centos5_dev.
…”

default[:repo][:my_centos][:updates_prd_6x] = “http://repo_centos6_dev.
…”

In a recipe, I have tried variations of the following:

If server is prod….

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev….

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be
more of how chef is handling the attributesd in the Compile Resource
Collection phase of a chef run…

I have different repos for each of my environments (dev, test, prod,
QA, stage1, personal) and different versions of centos for each of
these. Each points to a specific internal url.

Anyone have any ideas?


#6

Thanks everyone… This below worked…

From: likonar@gmail.com [mailto:likonar@gmail.com] On Behalf Of Max Gorbul
Sent: Thursday, February 02, 2012 4:29 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How to change the name of an attribute with an attribute?

another way is

prod_key = :“updates_prd_#{node[:platform_version].to_i}x”

dev_key = :“updates_dev_#{node[:platform_version].to_i}x”

Update_Repo = node[:repo][:my_centos][key_prod]

or

Update_Repo = node[:repo][:my_centos][key_dev]

–max

On Thu, Feb 2, 2012 at 1:26 PM, Max Gorbul max@gorbul.net wrote:

AJ meant that you can use Hash syntax or regular ruby method syntax.

node[:foo][:bar] is the same as node.foo.bar

–max

On Thu, Feb 2, 2012 at 1:23 PM, Van Fossan,Randy vanfossr@oclc.org wrote:

AJ,

Sorry, I am still just a newbie, I did not follow that…

-----Original Message-----
From: AJ Christensen [mailto:aj@junglist.gen.nz]
Sent: Thursday, February 02, 2012 4:10 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How to change the name of an attribute with an attribute?

node.foo.bar.send(“some_crazy_#{attribute_helper}_#{node[“bong”]}”)

–AJ

On 3 February 2012 10:08, Van Fossan,Randy vanfossr@oclc.org wrote:

Does anyone know how to change the “name of an attribute” with an
attribute? I know that sounds silly, but I want to subscribe to a set
of repos based on the platform version and the environment that the
server is in.

The attributes from the /attributes folder are:

default[:repo][:my_centos][:updates_prd_5x] =
“http://repo_centos5_prod…”

default[:repo][:my_centos][:updates_prd_6x] =
“http://repo_centos6_prod…”

default[:repo][:my_centos][:updates_dev_5x] = “http://repo_centos5_dev…”

default[:repo][:my_centos][:updates_prd_6x] = “http://repo_centos6_dev…”

In a recipe, I have tried variations of the following:

If server is prod….

Update_Repo =
node[:repo][:my_centos][:updates_prd_{node[:platform_version].to_i}x]

if server is dev….

Update_Repo =
node[:repo][:my_centos][:updates_dev_{node[:platform_version].to_i}x]

I cannot get the syntax down correctly. Although, I suspect it may be
more of how chef is handling the attributesd in the Compile Resource
Collection phase of a chef run…

I have different repos for each of my environments (dev, test, prod,
QA, stage1, personal) and different versions of centos for each of
these. Each points to a specific internal url.

Anyone have any ideas?