Where i can find chef server ip and hostname in a recipe for add variable to template


#1

Where i can find chef server ip and hostname in a recipe for add
variable to template

For example i have a recipe:

Creating true /etc/hosts

template “/etc/hosts” do
mode 0644
owner "root"
group "root"
source "etc/hosts.erb"
variables ({
:ip => node[:dc][:ip],
:domain => node[:dns][:domain],
:hostname => node[:dc][:hostname],
:chefserverip => ???,
:chefserverhostname => ???
})
action :create
end

and template:

127.0.0.1 localhost
<%= @chefserverip %> <%= @chefserverhostname %>.<%= @domain %>
<%= @ip %> <%= @hostname %>.<%= @domain %> <%= @hostname %>

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How I can access service variables ??? and ???

And for a future:

How can i know what service vars are present when recipes are run? My be
present a simple method or you hac a true doc url ?

Thank you very much.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev


#2

One way is to set the values in your client node.
Do a knife node edit and add the values chefserverip and chefserverhostname.
These will be accessible to all recipes.

You can also set recipe specific attributes.

On Wed, May 29, 2013 at 4:18 PM, Vladimir Skubriev
skubriev@cvisionlab.comwrote:

Where i can find chef server ip and hostname in a recipe for add variable
to template

For example i have a recipe:

Creating true /etc/hosts

template “/etc/hosts” do
mode 0644
owner "root"
group "root"
source "etc/hosts.erb"
variables ({
:ip => node[:dc][:ip],
:domain => node[:dns][:domain],
:hostname => node[:dc][:hostname],
:chefserverip => ???,
:chefserverhostname => ???
})
action :create
end

and template:

127.0.0.1 localhost
<%= @chefserverip %> <%= @chefserverhostname %>.<%= @domain %>
<%= @ip %> <%= @hostname %>.<%= @domain %> <%= @hostname %>

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How I can access service variables ??? and ???

And for a future:

How can i know what service vars are present when recipes are run? My be
present a simple method or you hac a true doc url ?

Thank you very much.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev


#3

On 29.05.2013 15:37, Mukta Aphale wrote:

One way is to set the values in your client node.
Do a knife node edit and add the values chefserverip and
chefserverhostname.
These will be accessible to all recipes.

You can also set recipe specific attributes.

On Wed, May 29, 2013 at 4:18 PM, Vladimir Skubriev
<skubriev@cvisionlab.com mailto:skubriev@cvisionlab.com> wrote:

Where i can find chef server ip and hostname in a recipe for add
variable to template

For example i have a recipe:

# Creating true /etc/hosts
template "/etc/hosts" do
    mode 0644
    owner "root"
    group "root"
    source "etc/hosts.erb"
    variables ({
                :ip => node[:dc][:ip],
                :domain => node[:dns][:domain],
                :hostname => node[:dc][:hostname],
                :chefserverip => ???????????????,
                :chefserverhostname => ???????????????
                })
    action :create
end


and template:

127.0.0.1           localhost
<%= @chefserverip %>           <%= @chefserverhostname %>.<%=
@domain %>
<%= @ip %>        <%= @hostname %>.<%= @domain %> <%= @hostname %>
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How I can access service variables ??????????????? and ???????????????

And for a future:

How can i know what service vars are present when recipes are run?
My be present a simple method or you hac a true doc url ?

Thank you very much.

-- 
Best regards,

CVision Lab System Administrator
Vladmir Skubriev

This is not true way. I think this vars must be present by default in
chef runtime.

Set vars in node, environment, data bag, etc - is not true.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev


#4

The method described is a valid one but not the easiest to maintain.

The values you’re looking for can be obtained from the Chef::Config hash
i.e.:

chef > Chef::Config[:chef_server_url]
=> "http://10.1.1.83:4000"
chef >

Note that the information is not available in the format exactly you’re
asking for. Another thing is you have a bit of a chicken and egg problem.
How are you able to run chef connected to the server if you don’t have the
DNS entry already? Is this just a failback for flakey DNS?

On Wed, May 29, 2013 at 7:39 AM, Vladimir Skubriev
skubriev@cvisionlab.comwrote:

On 29.05.2013 15:37, Mukta Aphale wrote:

One way is to set the values in your client node.
Do a knife node edit and add the values chefserverip and
chefserverhostname.
These will be accessible to all recipes.

You can also set recipe specific attributes.

On Wed, May 29, 2013 at 4:18 PM, Vladimir Skubriev <
skubriev@cvisionlab.com> wrote:

Where i can find chef server ip and hostname in a recipe for add
variable to template

For example i have a recipe:

Creating true /etc/hosts

template “/etc/hosts” do
mode 0644
owner "root"
group "root"
source "etc/hosts.erb"
variables ({
:ip => node[:dc][:ip],
:domain => node[:dns][:domain],
:hostname => node[:dc][:hostname],
:chefserverip => ???,
:chefserverhostname => ???
})
action :create
end

and template:

127.0.0.1 localhost
<%= @chefserverip %> <%= @chefserverhostname %>.<%= @domain %>
<%= @ip %> <%= @hostname %>.<%= @domain %> <%= @hostname %>

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How I can access service variables ??? and ???

And for a future:

How can i know what service vars are present when recipes are run? My be
present a simple method or you hac a true doc url ?

Thank you very much.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev

This is not true way. I think this vars must be present by default in
chef runtime.

Set vars in node, environment, data bag, etc - is not true.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev


#5

One other thing to add is that you might want to rethink your idea.
Using my previous email, you’ll have to parse out the Chef server url into
the hostname part and then do a lookup to get the ip address. Here’s where
this goes wrong:

  • First run, you extract the hostname and do a DNS lookup
  • Add that entry to the hosts file
  • Second run (with DNS offline for whatever reason) Chef will do a lookup
    again (remember that you have to seed the template variables so it can do
    an intermediary generation and compare with the existing file).

Two things can happen here:

  • Depending on how you code the lookup, it will either use the hosts file
    (which means you’re basically doing a noop)
  • or it will try the DNS lookup which will fail and then cause the chef run
    to fail

Again, you have to have the value in client.rb resolvable already or use an
ip address to even run Chef.

On Wed, May 29, 2013 at 8:09 AM, John E. Vincent (lusis) <
lusis.org+chef-list@gmail.com> wrote:

The method described is a valid one but not the easiest to maintain.

The values you’re looking for can be obtained from the Chef::Config hash
i.e.:

chef > Chef::Config[:chef_server_url]
=> "http://10.1.1.83:4000"
chef >

Note that the information is not available in the format exactly you’re
asking for. Another thing is you have a bit of a chicken and egg problem.
How are you able to run chef connected to the server if you don’t have the
DNS entry already? Is this just a failback for flakey DNS?

On Wed, May 29, 2013 at 7:39 AM, Vladimir Skubriev <
skubriev@cvisionlab.com> wrote:

On 29.05.2013 15:37, Mukta Aphale wrote:

One way is to set the values in your client node.
Do a knife node edit and add the values chefserverip and
chefserverhostname.
These will be accessible to all recipes.

You can also set recipe specific attributes.

On Wed, May 29, 2013 at 4:18 PM, Vladimir Skubriev <
skubriev@cvisionlab.com> wrote:

Where i can find chef server ip and hostname in a recipe for add
variable to template

For example i have a recipe:

Creating true /etc/hosts

template “/etc/hosts” do
mode 0644
owner "root"
group "root"
source "etc/hosts.erb"
variables ({
:ip => node[:dc][:ip],
:domain => node[:dns][:domain],
:hostname => node[:dc][:hostname],
:chefserverip => ???,
:chefserverhostname => ???
})
action :create
end

and template:

127.0.0.1 localhost
<%= @chefserverip %> <%= @chefserverhostname %>.<%= @domain %>
<%= @ip %> <%= @hostname %>.<%= @domain %> <%= @hostname %>

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

How I can access service variables ??? and ???

And for a future:

How can i know what service vars are present when recipes are run? My be
present a simple method or you hac a true doc url ?

Thank you very much.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev

This is not true way. I think this vars must be present by default in
chef runtime.

Set vars in node, environment, data bag, etc - is not true.


Best regards,

CVision Lab System Administrator
Vladmir Skubriev