| Server IP : 82.148.16.210 / Your IP : 216.73.216.19 Web Server : nginx/1.29.5 System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64 User : root ( 0) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/lib/cloudinit/config/ |
Upload File : |
"""
Create Etc Hosts
----------------
**Summary:** create ``/etc/hosts``
This module will create ``/etc/hosts`` file on first boot.
Management of ``/etc/hosts`` is controlled using ``create_etc_hosts``
directive.
If set to ``true`` , cloud-init will generate ``/etc/hosts``
using the template located in ``/etc/cloud/templates/create_hosts.dist.tmpl``.
In the ``/etc/cloud/templates/create_hosts.tmpl`` template, the strings
``$address``, ``$hostname`` and ``$fqdn`` will be replaced with the ipv4
address, hostname and fqdn respectively.
**Internal name:** ``cc_create_etc_hosts``
**Module frequency:** per instance
**Supported distros:** all
**Config keys**::
create_etc_hosts: <true/false>
localhost_interface: <interface>
"""
from cloudinit import templater
from cloudinit import util
from cloudinit.settings import PER_INSTANCE
frequency = PER_INSTANCE
def handle(name, cfg, cloud, log, _args):
create_hosts = util.get_cfg_option_str(cfg, "create_etc_hosts", False)
interface = util.get_cfg_option_str(cfg, "localhost_interface", 'eth0')
if util.translate_bool(create_hosts, addons=['template']):
(hostname, fqdn) = util.get_hostname_fqdn(cfg, cloud)
if not hostname:
log.warn(("Option 'create_etc_hosts' was set,"
" but no hostname was found"))
hostname = 'localhost'
address = util.get_ipv4_from_iface(interface)
# Render from a template file
tpl_fn_name = cloud.get_template_filename("create_hosts.%s" %
(cloud.distro.osfamily))
if not tpl_fn_name:
raise RuntimeError(("No hosts template could be"
" found for distro %s") %
(cloud.distro.osfamily))
templater.render_to_file(tpl_fn_name, '/etc/hosts',
{'hostname': hostname,
'fqdn': fqdn,
'address': address})
else:
log.debug(("Configuration option 'create_etc_hosts' is not set,"
" not creating /etc/hosts in module %s"), name)
# vi: ts=4 expandtab