Add variable for local IP address to /etc/hosts manager

Bug #1020695 reported by Peter Sankauskas
56
This bug affects 11 people
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Low
Peter Sankauskas
CentOS
New
Undecided
Unassigned

Bug Description

Hi,
>
> I would like to set first line in the /etc/hosts file to be something like
> this:
>
> local-ip FQDN Hostname
>
> The ip address should be the one returned from `ec2metadata --local-ipv4`.
> After this line, I would like the usual 127.0.0.1 localhost line. I have
> edited the template at /etc/cloud/templates/hosts.tmpl to have:
>
> ## The value '$hostname' will be replaced with the local-hostname
> 10.2.46.37 $fqdn $hostname
> 127.0.0.1 localhost

I guess it would be good to have a variable available for substitution
available. Could you open a bug on cloud-init for that?
http://bugs.launchpad.net/cloud-init/+filebug

> but I do not know how to get the local IP address as a variable to put into
> the template. At the moment, it is hardcoded, which is not ideal.
>
> Does anyone know what variable I can use in the template file?

The hack that I can think of is to add an upstart job or user-data hook
that just does this for you.

Anyone have better ideas?

Related branches

Scott Moser (smoser)
Changed in cloud-init:
importance: Undecided → Low
Revision history for this message
Peter Sankauskas (pas256) wrote :

Since this bug is a low priority, I figured I would download the source and figure it out. Attached is my proposed patch where I use netinfo.netdev_info() to get the data need to pass to the template.

This allows the use of variables such as $dev_lo, $dev_eth0, etc (depending on what devices are present on the server) to be used in hosts.ubuntu.tmpl.

Example:
$dev_eth0 $fqdn $hostname
127.0.0.1 localhost

Comments on the patch welcome.

Changed in cloud-init:
assignee: nobody → Peter Sankauskas (pas256)
Revision history for this message
Peter Sankauskas (pas256) wrote :

The above patch is for version 0.7.0 present on Ubuntu 12.10 Quantal

Revision history for this message
Peter Sankauskas (pas256) wrote :

Since Ubuntu 12.04 Precise is an LTS release, here is the patch for it as well.

Scott Moser (smoser)
Changed in cloud-init:
status: New → Triaged
Revision history for this message
Scott Moser (smoser) wrote :

Karate, Peter,
  Could you look at the merge proposal and let me know if it would work for you?
  I do think it would sovel the problem, and incorporates Peter's 'eth0_ip' idea in it, along with allowing for '$local_ipv4'

  https://code.launchpad.net/~smoser/cloud-init/lp1020695/+merge/163216

  I wrote it all out, but felt it was getting heavier than I wanted right before 0.7.2 release, which I want "real soon now".

Revision history for this message
Karate Vick (karate-vick) wrote : Re: [Bug 1020695] Re: Add variable for local IP address to /etc/hosts manager

Yes, it looks good. Getting the public_ipv4 should do the trick.

K

On Tue, May 14, 2013 at 12:47 PM, Scott Moser <email address hidden> wrote:

> Karate, Peter,
> Could you look at the merge proposal and let me know if it would work
> for you?
> I do think it would sovel the problem, and incorporates Peter's
> 'eth0_ip' idea in it, along with allowing for '$local_ipv4'
>
> https://code.launchpad.net/~smoser/cloud-init/lp1020695/+merge/163216
>
> I wrote it all out, but felt it was getting heavier than I wanted
> right before 0.7.2 release, which I want "real soon now".
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1020695
>
> Title:
> Add variable for local IP address to /etc/hosts manager
>
> Status in Init scripts for use on cloud images:
> Triaged
>
> Bug description:
> Hi,
> >
> > I would like to set first line in the /etc/hosts file to be something
> like
> > this:
> >
> > local-ip FQDN Hostname
> >
> > The ip address should be the one returned from `ec2metadata
> --local-ipv4`.
> > After this line, I would like the usual 127.0.0.1 localhost line. I
> have
> > edited the template at /etc/cloud/templates/hosts.tmpl to have:
> >
> > ## The value '$hostname' will be replaced with the local-hostname
> > 10.2.46.37 $fqdn $hostname
> > 127.0.0.1 localhost
>
> I guess it would be good to have a variable available for substitution
> available. Could you open a bug on cloud-init for that?
> http://bugs.launchpad.net/cloud-init/+filebug
>
> > but I do not know how to get the local IP address as a variable to put
> into
> > the template. At the moment, it is hardcoded, which is not ideal.
> >
> > Does anyone know what variable I can use in the template file?
>
> The hack that I can think of is to add an upstart job or user-data hook
> that just does this for you.
>
> Anyone have better ideas?
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/cloud-init/+bug/1020695/+subscriptions
>

Revision history for this message
cristi1979 (cristi-falcas) wrote :

did this get implemented after all?

I don't see it in the rpm from cloud-init 0.7.4 and I was curious if it was pushed or not.

Revision history for this message
datakid (datakid) wrote :

This still hasn't made it into 0.7.6. What's going on?

Revision history for this message
datakid (datakid) wrote :

Oh I see, the underlying code has been changed. This patch will no longer work.

Revision history for this message
Lior Goikhburg (goikhburg) wrote :

Is this ever going to be merged ?

Revision history for this message
eblock@nde.ag (eblock) wrote :

I'm currently using version 0.7.8 but the patch is still not there. It would be really useful, I hope it will be merged soon.

Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Triaged → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.