User data
scripts of Linux BMSs are customized by using the open-source Cloud-Init
architecture. This architecture uses BMS metadata as the data source for
automatically configuring the BMSs. The script types are compatible with
open-source Cloud-Init. For details about Cloud-Init, see http://cloudinit.readthedocs.io/en/latest/topics/format.html.
User-data
scripts are directly executed as shell scripts after they are passed into Linux
instances. User-data scripts have the following characteristics:
- The first line starts with a
number sign and an exclamation mark (#!).
- User-data scripts are run once
only the first time the instance starts.

Example:
#!/bin/sh
echo
"Hello World. The time is now $(date -R)!" | tee
/root/userdata_test.txt
The example user-data script can be run to write
the system time to the userdata_test.txt file the first time the instance
starts.
Cloud config data
Cloud-config is
a convenient way to pre-configure specific services (such as YUM repository
update, SSH key import, and dependency installation) for instances.
Cloud-config data has the following characteristics:
- The first line starts with
#cloud-config, and the header cannot include spaces.
- The script must follow the YAML
syntax.
- The
frequency at which the user data is run varies based on your configured
modules. For example, if you configure the Apt Configure module, the user data
is run only once for each instance. If you configure the Bootcmd module, the
user data is run each time the instance starts.

Example
#cloud-config
Apt:
Primary:
- Arches: [default]
Uri: https:
//us.archive.unbutu.com/unbutu/ Bootcmd:
- Echo: “Hello World. The
time is now $(date -R) !” | tee /root/userdata_test.txt
The example cloud-config data can be run to modify
the default software repository and write the latest system time to the
userdata_test.txt file each time the instance starts
Example 1
This case illustrates how to
inject user data so as to simplify BMS configuration.
In this
example, vim is configured to enable syntax highlighting, display line numbers,
and set the tab stop to 4. Configuration file .vimrc is created
and injected into the /root/.vimrc directory during BMS creation. After
the BMS is created, vim is automatically configured based on your requirements.
This helps to improve BMS configuration efficiency, especially when you are
creating BMSs in a batch.
The script is as follows:

#cloud-config
write_files:
- path: /root/.vimrc
content: |
syntax on set
tabstop=4 set
number
Example 2
This case illustrates how to inject user data so as to reset the
password for logging in to a Linux BMS.
In this example, the password of
user root will be reset to "******".
The script is as follows (retain the indentation in the following
script):

#cloud-config
chpasswd:
list: |
root:******
expire: False
After the BMS is created, you can use the new
password to log in to it. To ensure system security, change the password of
user root after logging in to the BMS for the first time.