File: update_hostname.rst

package info (click to toggle)
cloud-init 25.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,412 kB
  • sloc: python: 135,894; sh: 3,883; makefile: 141; javascript: 30; xml: 22
file content (67 lines) | stat: -rw-r--r-- 1,865 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
.. _cce-update-hostname:

Update hostname and FQDN
************************

For a full list of keys, refer to the
:ref:`update hostname module <mod_cc_update_hostname>` schema.

Default behavior
================

When ``preserve_hostname`` is not specified, cloud-init updates
``/etc/hostname`` per-boot based on the cloud-provided ``local-hostname``
setting. If you manually change ``/etc/hostname`` after boot, cloud-init will
no longer modify it.

This default cloud-init behavior is equivalent to this cloud-config:

.. literalinclude:: ../../../module-docs/cc_update_hostname/example1.yaml
   :language: yaml
   :linenos:

Note that the same cloud-config will also prevent cloud-init from updating the
system hostname.

Prevent updates to ``/etc/hostname``
====================================

This example will prevent cloud-init from updating the system hostname or
``/etc/hostname``.

.. literalinclude:: ../../../module-docs/cc_update_hostname/example2.yaml
   :language: yaml
   :linenos:

Set hostname
============

This example sets the hostname to ``external.fqdn.me`` instead of ``myhost``.

.. literalinclude:: ../../../module-docs/cc_update_hostname/example4.yaml
   :language: yaml
   :linenos:

Override meta-data
==================

Set the hostname to ``external`` instead of ``external.fqdn.me`` when
meta-data provides the ``local-hostname``: ``external.fqdn.me``.

.. literalinclude:: ../../../module-docs/cc_update_hostname/example5.yaml
   :language: yaml
   :linenos:

Don't create ``/etc/hostname`` file
===================================

On a machine without an ``/etc/hostname`` file, this config instructs
cloud-init not to create one.

In most clouds, this will result in a DHCP-configured hostname provided by the
cloud.

.. literalinclude:: ../../../module-docs/cc_update_hostname/example6.yaml
   :language: yaml
   :linenos: