Search code examples
chef-infrachef-recipechef-soloaws-opsworks

How to work with dynamic variable in file chef resource?


When we work with template chef resource, then <%= node["fqdn"] %> will modify with node's fqdn. I want to do this using file resource. I have a file abc.txt and <%= node["fqdn"] %> or any other variable inside it. How to change this variable with actual value when chef-client runs.

This is my file resource -->

file "/home/user/test.txt" do
  content IO.read("/opt/cheftest/abc.txt")
  mode '0755'
  action :create
end

Above copies content of abc.txt in test.txt as it is without changing variable name with actual values. How to change variables with actual values ?


Solution

  • I think what you are asking for is the local property on the template resource, but it is hard to tell. Normally you would just use a plain old template resource unless you have a really good reason.