UserData
UserData is the user custom content exposed to the guest instance by the currently deployed and running cloud infrastructure.
Its purpose is to provide additional data for the instance to customize it as much as you need, the vServer cloud service does support this feature.
VNG Cloud is able to interpret and use this kind of user specific data in multiple ways. In most of the cases, the thing that indicates of what type is the processed data is usually the first line.
Batch
PowerShell
Bash
Python
Cloud config
Initialize UserData when activating vServer
Suggestions for filling commands for UserData
Batch
rem cmd
This file is executed in a cmd.exe shell (can be changed with the COMSPEC environment variable).
PowerShell
#ps1 or #ps1_sysnative (system native)
#ps1_x86 (Windows On Windows 32bit)
Execute PowerShell scripts using the desired executable.
Bash
#!/bin/bash
A bash shell needs to be installed in the system and available in the PATH in order to use this feature.
Python
#!/usr/bin/env python
Python is available by default with the build itself, but also it must be in the system PATH.
Cloud config
#cloud-config
Cloud-config YAML configuration as support by cloud-init, excluding Linux specific content. The following cloud-config directive are supported:
write_files: Definenes a set of files which will be created on the local filesystem. It can be a list of items or only one item, with the following attributes:
path: Absolute path on disk where the content should be written.
content: The content which will be written in the given file.
permissions: Integer representing file permissions.
encoding: The encoding of the data in content. Supported encodings are:
b64, base64 for base64-encoding content;
gz,gzip for gzip encoded content;
gz+b64,gz+base64,gzip+b64,gzip+base64 for base64 encoded gzip content.
Example:
set_timezone: Change the underlying timezone.
Example:
set_hostname: Override the already default set hostname value (taken from metadata). If the hostname is changed, a reboot will be required.
Example:
groups: Create local groups and add existing users to those local groups.
The definition of the groups consists of a list in the format:
<group_name>: [<user1>,<user2>]
List of users can be empty, when creating a group without members.
Example:
users: Create and configure local users.
the users are defined as a list. Each element from the list represents a user. Each user can have the following attributes defined:
name: (required string) The username;
gecos: The user description;
primary_group: the user's primary group;
groups: the user's group. On Windows, primary_group and groups are concatenated.
passwd: the user's password. On Linux, the password is a hashed string, whereas on Windows the password is a plaintext string. If the password is not defined, a random password will be set.
inactive: boolean value, defaults to False. If set to True, the user will be disabled.
expiredate: a string in the format <year>-<month>-<day>. Example: 2020-10-01.
ssh_authorized_keys: a list of SSH public keys, that will be set in ~/.ssh/authorized_keys .
Example:
ntp: Set NTP servers. The definition is a dict with the following attributes:
enabled: Boolean value, default to True, to enable or disable the NTP config;
servers: A list of NTP servers;
pools: A list of NTP pools.
the Server and pools are aggregated, servers being the first ones in the list. On Windows, there is no difference between an NTP pool or server.
Example:
runcmd: Directive that can contain a list of commands that will be executed, in the order of their defination.
A command can be defined as a string or as a list of strings, the first one being the executable path.
On windows, the commands are aggregated into a file and executed with cmd.exe.
Example:
The cloud-config directives are executed by default in the following order:
write_files;
set_timezone;
set_hostname
ntp;
groups;
users;
runcmd;
Use config option cloud_config_plugins to filter or to change the order of the cloud config plugins.
The execution of set_hostname or runcmd can request a reboot if needed. the reboot is performed at the end of the cloud-config execution (after all the directives have been executed .
To type the command lines to provide Userdata to Server, you can implement in Create-Server step (step 4 in Getting stared vServer in here):
In step "Network setting" to configure UserData, you could select "UserData" option, as shown below:
You able to upload the file or input the command lines into content field to execute providing user information to Server. Refer to the section "Suggestions for filling commands for UserData", VNG Cloud provided defaults script command suggestions to configure.
If UseData information in the tools being used has been Base64 encoded, you will select it.
When creating Windows Severs, VNG Cloud provide Khi tạo Server Windows, VNG Cloud Default commands (Default Scripts) in UserData field, including Windows OS licences that you can use immediately:
Include:
stackops VngP@ssword2 : Username and password of OS;
N69G4-B89J2-4G8F4-WWYCC-J464C : is activation key of OS, system will automatically map with the corresponding key and OS:
The result will be displayed by default:
Note:
Windows license usage is authenticated according to the IP where the VM purchased the license, then system will active the license.
Last updated