Overriding the hostname in a solo stroller recipe

Having written my first recipe for a solo tramp, I realized something as simple as changing the host name. In a stray file, I have this;

config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "../../chef/cookbooks" chef.roles_path = "../../chef/roles" chef.data_bags_path = "../../chef/data_bags" chef.json = { :hostname => "foofoo" } chef.add_recipe "myrecipe" 

in myrecipe / recipes / default.rb;

 myvar = node[:hostname] template "/tmp/myfile" do source "myfile.erb" owner "root" group "root" mode 0644 variables( :myvar => myvar ) end 

in myrecipe / templates / default / myfile.erb;

 <%= @myvar %> 

This does not work. / tmp / myfile all the time ends with the real host name from / etc / hostname. After I hit my head, I pressed on these changes;

in a stray file;

 chef.json = { :myhostname => "foofoo" } 

in the recipe file;

 myvar = node[:myhostname] 

So it seems that: "hostname" is somehow special, but as I can, I cannot find any documentation that explains why or how to override it, or what other "special" values ​​may be available.

Most of the documentation seems to imply a certain level of competency that I have not yet reached. So, I could see the answer and did not recognize it. Can someone point me to the “absolute beginners” who will explain this?

+1
source share
1 answer

Firstly: it was my first experiments with a chef and: changing the host name ist not the simplest thing to do (because for the rest of the chef the old host name remains so you need to do ugly things to restart Chef and t .d.); -)

Secondly: node['hostname'] is special (this is the so-called automatic attribute ), it is updated from the target host via ohai so that you can use it in your templates, for example.

Edit: you can use this cooking to use the hostname.

+1
source

Source: https://habr.com/ru/post/1481189/


All Articles