Skip to content

Collection of 'user data' to init OS for different server roles with cloud-init or shell scripts

License

Notifications You must be signed in to change notification settings

cloud-simple/user-data

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collection of 'user data' scripts to initialize server OS for various roles

'User data' are used to initialize OS during instance creation and can be used both for Clouds and for on-premise deployments. For GCP VM the term 'startup scripts' is used.

Get more details on how to use 'user data' in Clouds with the following documentation:

Directory structure

'User data' are stored as user-data scripts using the OS/app/component/ directory structure consisted with the following aggregation layers:

  • OS - operation system layer, e.g.: ubuntu
  • app - application layer, e.g.: ciscat
    • for general (application-agnostic) components it is possible to use something like general as the names for this layer
  • component - particular application component, e.g.: mysql or tomcat or docker

Usage

The included user-data scripts can be passed to instances being created using cloud-init, see below the examples for AWS EC2, or can be launched on the running instances using sudo <path to user-data script> commands.

How to test 'user data' using AWS EC2 instances

Note

Make sure that your aws cli configuration is set up accordingly. You can check configured settings in the following way

  • Use the following command to show your configured identity which will be used in the further example
    • aws sts get-caller-identity --query "Arn" --output text
  • Use the following command to show your configured AWS region which will be used in the further example
    • aws configure get region

The repo includes auxiliary scripts to test provided 'user data' with help of AWS infrastructure. To use them follow these steps:

  • Clone the repo
    • git clone https://github.com/mtilson/user-data.git
  • Change to testing/aws-ec2 directory
    • cd user-data/testing/aws-ec2
  • Create .env-xxx file defining the following variables (see the section Example .env files below)
count:          number of EC2 instances to be created; default is '1' if omitted
instance_type:  type of the EC2 instances; default is 't2.micro' if omitted
os_name:        OS name the instance to be based on; required - should be one of the `map_os_ssm` array key defined in file `testing/aws-ec2/maps_aws`, e.g: "ubuntu-18.04" or "ubuntu-20.04")
key_name:       EC2 Key Pair name to be used to access the instances; required
sg_name:        Security Group name for the instances; required
vpc:            VPC ID to place instance to; default is VPC for which value of 'isDefault' attribute is 'true'
subnet:         Subnet ID to place instance to; default is the first (logical) subnet in the selected VPC
tag_name:       value of instances `Name` tag; default is 'general' if omitted
tag_type:       value of instances `Type` tag; default is 'mtilson/user-data' if omitted
user_data_file: path to the tested `user-data` file to be used for instance initialization; default is '../../misc/stub' if omitted
tg_name:        EC2 Target Group name the instance to be added as a target to; if omitted instance is not added to target group 
  • Run the command to create corresponding EC2 instances
    • ./create.sh .env-xxx
  • Run the command to list the created EC2 instances
    • ./list.sh .env-xxx
  • Run the command to delete the created EC2 instances
    • ./delete.sh .env-xxx

Example .env files


Docker on Ubuntu 18.04

count=1
instance_type="t2.micro"
os_name="ubuntu-18.04"
key_name="my_key_pair_name"      # replace the value with the name of corresponding key pair
sg_name="my_security_group_name" # replace the value with the name of corresponding security group
tag_name="docker"
tag_type="mtilson/docker"
user_data_file="../../ubuntu/18.04/general/docker/user-data"
  • user-data file used
  • Example commands to run
    • ./create.sh .env.ubuntu-18.04.general.docker
    • ./list.sh .env.ubuntu-18.04.general.docker
    • ssh <user>@<host_ip> -i <path to my_key_pair private key>
      • <user> and <host_ip> are provided as an output of the ./list.sh ... command
      • <path to my_key_pair private key> corresponding to the EC2 Key Pair
    • ./delete.sh .env.ubuntu-18.04.general.docker

Mysql 5 server for CIS-CAT Pro Dashboard on Ubuntu 18.04

count=1
instance_type="t2.micro"
os_name="ubuntu-18.04"
key_name="my_key_pair_name"      # replace the value with the name of corresponding key pair
sg_name="my_security_group_name" # replace the value with the name of corresponding security group
tag_name="mysql"
tag_type="mtilson/ciscat"
user_data_file="../../ubuntu/18.04/ciscat/mysql/user-data"
  • user-data file used
  • Example commands to run
    • ./create.sh .env.ubuntu-18.04.ciscat.mysql
    • ./list.sh .env.ubuntu-18.04.ciscat.mysql
    • ssh <user>@<host_ip> -i <path to my_key_pair private key>
      • <user> and <host_ip> are provided as an output of the ./list.sh ... command
      • <path to my_key_pair private key> corresponding to the EC2 Key Pair
    • ./delete.sh .env.ubuntu-18.04.ciscat.mysql

Tomcat 9 server for CIS-CAT Pro Dashboard on Ubuntu 18.04

count=1
instance_type="t2.micro"
os_name="ubuntu-18.04"
key_name="my_key_pair_name"      # replace the value with the name of corresponding key pair
sg_name="my_security_group_name" # replace the value with the name of corresponding security group
tag_name="tomcat"
tag_type="mtilson/ciscat"
user_data_file="../../ubuntu/18.04/ciscat/tomcat/user-data"
tg_name="ciscat"
  • user-data file used
  • Example commands to run
    • ./create.sh .env.ubuntu-18.04.ciscat.tomcat
    • ./list.sh .env.ubuntu-18.04.ciscat.tomcat
    • ssh <user>@<host_ip> -i <path to my_key_pair private key>
      • <user> and <host_ip> are provided as an output of the ./list.sh ... command
      • <path to my_key_pair private key> corresponding to the EC2 Key Pair
    • ./delete.sh .env.ubuntu-18.04.ciscat.tomcat

About

Collection of 'user data' to init OS for different server roles with cloud-init or shell scripts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%