Add variable for local IP address to /etc/hosts manager
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/
>
> ## 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://
> 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
- Joshua Harlow (community): Needs Fixing
-
Diff: 258 lines (+145/-23)6 files modifiedcloudinit/config/cc_update_etc_hosts.py (+50/-11)
cloudinit/settings.py (+11/-0)
doc/examples/cloud-config.txt (+19/-4)
templates/hosts.debian.tmpl (+6/-4)
templates/hosts.redhat.tmpl (+6/-4)
tests/unittests/test_handler/test_handler_etc_hosts.py (+53/-0)
- Chad Smith: Disapprove
- Server Team CI bot: Approve (continuous-integration)
-
Diff: 70 lines (+23/-0)2 files modifiedcloudinit/config/cc_chef.py (+10/-0)
cloudinit/util.py (+13/-0)
Changed in cloud-init: | |
importance: | Undecided → Low |
Changed in cloud-init: | |
status: | New → Triaged |
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.