- From: "Julian C. Dunn" <
>
- To: "
" <
>
- Subject: [chef] Re: best way to run something only once?
- Date: Wed, 18 Jun 2014 21:25:16 -0700
Another commonly-used option, rather than writing random garbage to
the filesystem, is to persist some flag in the node object itself
using "set" (one of the few instances in which set/normal is actually
desirable). Example:
https://github.com/hw-cookbooks/postgresql/blob/develop/recipes/server.rb#L47
- Julian
On Wed, Jun 18, 2014 at 3:34 PM, Tomasz Chmielewski
<
>
wrote:
>
Does chef have some built-in way to run some recipes (or parts of it)
>
once only?
>
>
Say, I have the following (here, bash snippet, but could be anything):
>
>
bash 'adjust-supervisor' do
>
code <<-EOF
>
...some_code...
>
EOF
>
end
>
>
>
How would you approach to make sure it only runs once?
>
>
I figured I could use something like this in the recipe:
>
>
not_if { ::File.exists?("/etc/chef/stamps/some-description.stamp") }
>
>
followed by:
>
>
file "/etc/chef/stamps/some-description.stamp" do
>
owner "root"
>
group "root"
>
mode "0644"
>
action :create
>
end
>
>
>
It allows me to easily re-run by removing the stamp file, if needed.
>
>
>
But not sure it's the optimal way to make sure we run a given thing
>
once.
>
>
How do you approach this?
>
>
>
>
>
--
>
Tomasz Chmielewski
>
http://www.sslrack.com
--
[ Julian C. Dunn
<
>
* Sorry, I'm ]
[ WWW:
http://www.aquezada.com/staff/julian * only Web 1.0 ]
[
gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]
Archive powered by MHonArc 2.6.16.