Newb question: How to extend a resource?


#1

Hi! Newb here, coming from the puppet world!! Seems that it’s kinda easy
to mangle chef, so I’m looking for the chefiest way and would appreciate
some advice . . .

I would like to extend the remote_file resource so that it brings down a
new file if the name of the file on disk does not match that of the remote
resource (The name of the remote resource would change due to an attribute
change)

Any advice on how to approach this would be greatly appreciated!

regards,
Guy Matz


#2

Hi Guy,

I’d like to understand what you’re trying to achieve here. Consider:

in attributes:

default[‘mything’][‘version’] = ‘1.0’

in recipe:

remote_file “/tmp/foo” do
source "http://mysite.com/foo-version-#{node[‘mything’][‘version’]}.zip"
end

Then every time chef runs, it will look up the attribute, resolve it to a
string, and use that as part of the source.

If anywhere along the attribute inheritance model I change that to be
something else, say:

override[‘mything’][‘version’] = ‘2.5’

Then the resulting file on the system should still be ‘/tmp/foo’.

Does that answer the problem?
-M

On Tue, Aug 13, 2013 at 10:19 AM, Guy Matz guymatz@gmail.com wrote:

Hi! Newb here, coming from the puppet world!! Seems that it’s kinda easy
to mangle chef, so I’m looking for the chefiest way and would appreciate
some advice . . .

I would like to extend the remote_file resource so that it brings down a
new file if the name of the file on disk does not match that of the remote
resource (The name of the remote resource would change due to an attribute
change)

Any advice on how to approach this would be greatly appreciated!

regards,
Guy Matz


#3

Chef 11.6.0 will also use etags or last-modified headers so that if
/tmp/foo hasn’t been tampered with it won’t redownload from the source
over and over again. So that simple example should work pretty nicely.

In previous versions of Chef, you would have wanted to cache the zip
file somewhere and do a not_if { File.exists? } and then when it
downloaded trigger an execute to copy it from the cache into place at
/tmp/foo, or else to use the checksum attribute on remote_file to avoid
it re-downloading.

On 8/13/13 7:34 AM, Mike wrote:

Hi Guy,

I’d like to understand what you’re trying to achieve here. Consider:

in attributes:

default[‘mything’][‘version’] = ‘1.0’

in recipe:

remote_file “/tmp/foo” do
source
"http://mysite.com/foo-version-#{node[‘mything’][‘version’]}.zip
http://mysite.com/foo-version-#{node[‘mything’][‘version’]}.zip"
end

Then every time chef runs, it will look up the attribute, resolve it
to a string, and use that as part of the source.

If anywhere along the attribute inheritance model I change that to be
something else, say:

override[‘mything’][‘version’] = ‘2.5’

Then the resulting file on the system should still be ‘/tmp/foo’.

Does that answer the problem?
-M

On Tue, Aug 13, 2013 at 10:19 AM, Guy Matz <guymatz@gmail.com
mailto:guymatz@gmail.com> wrote:

Hi!  Newb here, coming from the puppet world!!  Seems that it's
kinda easy to mangle chef, so I'm looking for the chefiest way and
would appreciate some advice . . .

I would like to extend the remote_file resource so that it brings
down a new file if  the name of the file on disk does not match
that of the remote resource (The name of the remote resource would
change due to an attribute change)

Any advice on how to approach this would be greatly appreciated!

regards,
Guy Matz