How to: Use Ubiquity Cloud User Data Variables


Our development team has made several user data variables available for usage within the customizable cloud-config scripts on our cloud platform. The implementation of these variables into your cloud-config scripts provides access to otherwise unknown variables in the deployment process, which enables further automation possibilities on our platform.

User data variables can be utilized in one of two ways: by adding them to your cloud-config(s) within the Update User Data feature on our cloud order form or by including them in the user data parameter of our API’s cloud.create function. Below, we will detail the values that will be returned when setting these variables in your cloud-config scripts, and additionally provide an example implementation utilizing several of these variables.

User Data Variables

The majority of user data variables made available are limited in scope to the network configuration settings of the cloud instance being deployed. However, our developers have provided a few user account variables as well that may benefit you depending on your intended objective(s).

Each user data variable is delimited by two percentage signs at the beginning and end of the variable name, which allows them to be correctly interpreted as valid user data variables on our cloud platform. For a breakdown of each variable and an example use case, continue reading.

User Variables

%%root_user%% – Returns ‘root’ for any Linux-based operating systems.

%%root_pass_hash%% – Returns the root password in hash format.

%%root_pass%% – Returns the randomly generated root/administrator password.

%%email%% – Returns the primary email address associated with the account.

Network Variables

%%hostname%% – Returns the hostname set during the order process.

%%defaultgateway%% – Returns the default route in which network traffic passes through.

Private Network Variables

%%private_ip%% – Returns the private network address assigned.

%%private_subnet_prefix%% – Returns the private network address CIDR prefix number.

%%private_subnet_netmask%% – Returns the private network subnet mask for the private IP address.

%%private_subnet_gateway%% – Returns the private network gateway address.

%%private_subnet_network%% – Returns the private network address.

%%private_subnet_broadcast%% – Returns the private network broadcast address.

Public Network Variables

%%public_ip%% – Returns the public IP address assigned.

%%public_subnet_prefix%% – Returns the public network address CIDR prefix number.

%%public_subnet_netmask%% – Returns the public network subnet mask for the public IP address.

%%public_subnet_gateway%% – Returns the public network gateway address.

%%public_subnet_network%% – Returns the public network address.

%%public_subnet_broadcast%% – Returns the public network broadcast address.

Example Variable Outputs
%%root_user%% => root
%%root_pass%% => @e0X7txXNVNGzfu
%%root_pass_hash%% => /
%%email%% =>

%%hostname%% => MyCloudHostname
%%defaultgateway%% =>

%%private_subnet_prefix%% => 24
%%private_ip%% =>
%%private_subnet_netmask%% =>
%%private_subnet_gateway%% =>
%%private_subnet_network%% =>
%%private_subnet_broadcast%% =>

%%public_subnet_prefix%% => 22
%%public_ip%% =>
%%public_subnet_netmask%% =>
%%public_subnet_gateway%% =>
%%public_subnet_network%% =>
%%public_subnet_broadcast%% =>

Example Cloud-config Utilizing User Data Variables

The cloud-config provided below is the default for our CentOS 7.x template with the addition of installation and configuration file updates for Apache added to the runcmd section. After the Apache web server has been installed, we use the sed file/stream editor to find and update two default configuration parameter lines in /etc/httpd/conf/httpd.conf: ServerName and ServerAdmin. The ServerAdmin line is updated using the %%email%% user data variable while the ServerName line is updated to the %%hostname%% user data variable. By doing so, we avoid having to manually update these files and automate a customized Apache web server configuration.

ssh_pwauth: True
manage_etc_hosts: True
  - path: /etc/sysconfig/network-scripts/ifcfg-eth0
    permissions: '0644'
    owner: root:root
    content: |
  - path: /etc/sysconfig/network-scripts/ifcfg-eth1
    permissions: '0644'
    owner: root:root
    content: |
  - path: /etc/sysconfig/network-scripts/route-eth0
    permissions: '0644'
    owner: root:root
    content: | via %%dhcp_ip_public%% dev eth0
 - echo 'root:%%root_pass_hash%%' | chpasswd -e
 - ip route flush table all
 - ifdown eth0; ifdown eth1
 - ifup eth0; ifup eth1
 - yum clean all
 - yum -y update
 - yum install httpd -y
 - sed -i "s/#ServerName %%hostname%%/g" /etc/httpd/conf/httpd.conf
 - sed -i "s/ServerAdmin root@localhost/ServerAdmin %%email%%/g" /etc/httpd/conf/httpd.conf
 - systemctl restart httpd

Written by
on December 30, 2015

Facebook Twitter Google+ LinkedIn Addthis