From a3a435aafcddde2782939da7bf500ed69cff1c8d Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 1 Jun 2017 13:24:20 -0600 Subject: [PATCH] Update cloud-init configuration, add launch script Update cloud-init configuration per discussion with Dusty Mabe in #atomic on IRC (to fix circular dependency between docker and docker-storage-setup). Add launch script to make it easier. Signed-off-by: Scott Lowe --- .../docker-cloudinit/cloud-config.yml | 24 +++++------ centos-atomic/docker-cloudinit/launch.sh | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+), 12 deletions(-) create mode 100755 centos-atomic/docker-cloudinit/launch.sh diff --git a/centos-atomic/docker-cloudinit/cloud-config.yml b/centos-atomic/docker-cloudinit/cloud-config.yml index db82cf6..49d9836 100644 --- a/centos-atomic/docker-cloudinit/cloud-config.yml +++ b/centos-atomic/docker-cloudinit/cloud-config.yml @@ -2,20 +2,18 @@ # vim: syntax=yaml groups: - - docker: [root,centos] -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChbmG4wPh/f5CtB5hmepkUHwLKCBXuVX7CcxryMDfXx4W/2ffLO9J/Ek1w58ED3o5/KExduXjwtpMAvOoBffJsaSmm+Tc1NwzyR7GZ75MJYE1/5z5gkBUkZpjmM6qXCpiD6m3jIbaSxxfNEBL64i6H+UL6Ak1LKuYCLutTex+f4Q0NgJvRQyyG2Ms04egWjp91Kbd/cTA3/zfXGI2T3ZvGScvLcUE/neUgBloykuYi0k+VcFK0RAPjqfITaZXs6vtcPLXSX6CR4eHwgM8WpfO3sCEFkMwIhystAFapzSRdfHgtln0XZz84iydcvZVW1o3W8FTiOoNxDoC9ph6XmlU3 scott.lowe@scottlowe.org + - docker: [centos,root] write_files: - content: | [Unit] Description=UNIX Socket for the Docker API - PartOf=docker.service [Socket] ListenStream=/var/run/docker.sock SocketMode=0660 SocketUser=root SocketGroup=docker + Service=docker.service [Install] WantedBy=sockets.target @@ -54,11 +52,13 @@ write_files: owner: root:root permissions: '0644' runcmd: - - systemctl daemon-reload - - systemctl enable docker.service - - systemctl enable docker.socket - - systemctl enable docker-tcp.socket - - systemctl stop docker.service - - systemctl start docker.socket - - systemctl start docker-tcp.socket - - systemctl start docker.service + - [ systemctl, start, docker-storage-setup ] + - [ systemctl, mask, docker-storage-setup ] + - [ systemctl, daemon-reload ] + - [ systemctl, enable, docker.service ] + - [ systemctl, enable, docker.socket ] + - [ systemctl, enable, docker-tcp.socket ] + - [ systemctl, stop, docker.service ] + - [ systemctl, start, docker.socket ] + - [ systemctl, start, docker-tcp.socket ] + - [ systemctl, start, docker.service ] diff --git a/centos-atomic/docker-cloudinit/launch.sh b/centos-atomic/docker-cloudinit/launch.sh new file mode 100755 index 0000000..e657d2c --- /dev/null +++ b/centos-atomic/docker-cloudinit/launch.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# This script assumes AWSCLI is installed and configured correctly + +# Set some variables to be used later +TYPE="t2.micro" +KEYNAME="aws_rsa" + +# First, capture the ID of the user's default VPC +VPC_ID=$(aws --output text ec2 describe-vpcs \ + --filters Name=isDefault,Values=true \ + --query 'Vpcs[0].VpcId') + +# Use the captured VPC_ID to get the subnet ID of the first subnet +# in the first (sorted alphabetically) availability zone in the user's +# configured region +SN_ID=$(aws --output text ec2 describe-subnets \ + --filters Name=vpc-id,Values="$VPC_ID" \ + --query 'sort_by(Subnets,&AvailabilityZone)[0].SubnetId') + +# Capture the ID of the security group named "default" in the +# user's default VPC. +SG_ID=$(aws --output text ec2 describe-security-groups \ + --filters Name=group-name,Values="default" \ + Name=vpc-id,Values="$VPC_ID" \ + --query 'SecurityGroups[0].GroupId') + +# Capture the AMI ID for the latest version of CentOS 7 Atomic Host +IMG_ID=$(aws --output text ec2 describe-images \ + --owners 410186602215 \ + --filters Name=name,Values="*CentOS Atomic*" \ + --query 'sort_by(Images,&CreationDate)[-1].ImageId') + +# Launch an instance using the captured information from above (no cloud-init) +#aws ec2 run-instances --image-id $IMG_ID --instance-type $TYPE \ +#--key-name $KEYNAME --subnet-id $SN_ID --security-group-ids $SG_ID + +# Launch an instance using the captured information from above (with cloud-init) +aws ec2 run-instances --image-id $IMG_ID --instance-type $TYPE \ +--key-name $KEYNAME --user-data file://cloud-config.yml \ +--subnet-id $SN_ID --security-group-ids $SG_ID