- From: Nick Bryant <
>
- To:
- Subject: [chef] Re: Re: Inserting files into templates
- Date: Wed, 11 Sep 2013 22:10:19 +1000
Hey Jek,
Thanks for the response. You hit the nail on the head, the template
was being evaluated when the variable had no content...
I tried using 'action: nothing' in the template and doing a 'notifies:
create' from the ruby block, but sadly it still didn't work.
Seems putting dynamic content into the template resource is pretty difficult!
Thanks anyhow,
Nick
On 10 September 2013 17:27, Jek Sirex
<
>
wrote:
>
>
grabbed_data on compile-time is ''. Also templates' variables are built on
>
compile-time. As result you have built wrong template resource.
>
You have to move out `File.read` from ruby_block or read file inside
>
template (not sure).
>
It is very very very very important for you (and for me, when I started to
>
learn chef) to completely understand `anatomy of chef_run`.
>
http://docs.opscode.com/essentials_nodes_chef_run.html
>
>
>
2013/9/10 Nick Bryant
>
<
>
>
>
>
> Hi,
>
>
>
> New to chef, be gentle.
>
>
>
> I'm trying to write output from a web server into a template, but for
>
> some reason can't make the data available to the template.
>
>
>
> In my recipe I have:
>
>
>
> # Set a location for the grabbed data
>
> my_file = Chef::Config[:file_cache_path] + '/http_output.php'
>
>
>
> # Grab the data and write the file if it doesn't exist
>
> remote_file my_file do
>
> source 'http://example.com/data_to_grab.html'
>
> action :create_if_missing
>
> mode 0644
>
> end
>
>
>
> #declare globally
>
> gabbed_data = ''
>
>
>
> #read the data into a variable
>
> ruby_block 'read-grabbed-data' do
>
> block do
>
> grabbed_data = File.read(my_file)
>
> end
>
> action :create
>
> end
>
>
>
> # use the grabbed data in a template
>
> template node['myapp']['path'] + '/config.php' do
>
> source 'config.php.erb'
>
> mode 0755
>
> owner 'root'
>
> group 'root'
>
> variables(
>
> :password => node['myapp']['password'],
>
> :my_file => grabbed_data)
>
> end
>
>
>
>
>
> The template creates the config.php but doesn't output anything for
>
> the my_file part. I've checked inside the block that the data is read,
>
> and it is. I've also replaced grabbed_data with a string in the
>
> template, and it makes it into the config.php output so the template
>
> is good. I'm guessing it's something to do with the scope of the
>
> variable not being available to the template.
>
>
>
> Any ideas?
>
>
>
> N
>
>
Archive powered by MHonArc 2.6.16.