How to move/copy files locally with Chef -
i haven't yet come across chef resource copy/move files locally. example, want download jetty hightide , unzip it. once done, copy files particular folder, this:
# mv /var/tmp/jetty-hightide-7.4.5.v20110725/* /opt/jetty/
btw, jettyhightide when unzipped, gives folder , inside folder rest of files located. hence unzip jetty-hightide-7.4.5.v20110725.zip -d /opt/jetty/
useless because create directory /opt/jetty/jetty-hightide-7.4.5.v20110725/*
whereas want /opt/jetty/*
. hence looking local copy/move resource in chef.
how copy single file
first way
i use file
statement copy file (compile-time check)
file "/etc/init.d/someservice" owner 'root' group 'root' mode 0755 content ::file.open("/home/someservice").read action :create end
here :
"/etc/init.d/someservice"
- target file,"/home/someservice"
- source file
also can wrap ::file.open("/home/someservice").read
in lazy
block
... lazy { ::file.open("/home/someservice").read } ...
second way
user remote_file
statement (run-time check)
remote_file "copy service file" path "/etc/init.d/someservice" source "file:///home/someservice" owner 'root' group 'root' mode 0755 end
third way
also can use shell/batch
for-each directory
dir[ "/some/directory/resources/**/*" ].each |curr_path| file "/some/target/dir/#{pathname.new(curr_path).basename}" owner 'root' group 'root' mode 0755 content lazy { io.read(curr_path, mode: 'rb').read } action :create end if file.file?(curr_path) directory "/some/target/dir/#{file.dirname(curr_path)}" path curr_path owner 'root' group 'root' mode 0755 action :create end if file.directory?(curr_path) end
this idea, because sub-paths in example not handled correctly.
Comments
Post a Comment