Skip to content

Instantly share code, notes, and snippets.

@krenz444
Created October 5, 2015 20:04
Show Gist options
  • Save krenz444/aec3959c9610e1b7f943 to your computer and use it in GitHub Desktop.
Save krenz444/aec3959c9610e1b7f943 to your computer and use it in GitHub Desktop.
description: >
Heat template for Cloudbreak
parameters:
key_name:
type: string
description : Name of a KeyPair to enable SSH access to the instance
image_id:
type: string
description: ID of the image
app_net_cidr:
type: string
description: app network address (CIDR notation)
public_net_id:
type: string
description: The ID of the public network. You will need to replace it with your DevStack public network ID
resources:
app_network:
type: OS::Neutron::Net
properties:
admin_state_up: true
name: app_network
app_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: app_network }
cidr: { get_param: app_net_cidr }
router:
type: OS::Neutron::Router
router_gateway:
type: OS::Neutron::RouterGateway
properties:
router_id: { get_resource: router }
network_id: { get_param: public_net_id }
router_interface:
type: OS::Neutron::RouterInterface
properties:
router_id: { get_resource: router }
subnet_id: { get_resource: app_subnet }
gw_user_data_config:
type: OS::Heat::SoftwareConfig
properties:
config: |
#!/bin/bash
set -x
START_LABEL=97
PLATFORM_DISK_PREFIX=vd
setup_tmp_ssh() {
echo "#tmpssh_start" >> /home/ec2-user/.ssh/authorized_keys
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCO+ZWmiWaHTM5G1H0YLhe6lR+GQoPjCPklbTYjhmu/4KTtfzLulPCpiS3gSLyj0jpSE/BwRDgCAif/kJ+Yq2Hoh56cflNKCvM/SQ659Xldzq4RvOGVIo1SvOMgjMJnN2sKdQQzfuDPIIJGxznlUv8SAyaIR6fiRAuIALGoNPDfZQgiqrjWAtHiE7Bo9tv03fPYOq7KBNcOEbTgc+a9xEu2n3e4kZ86XjgfpfxIcgOfR5kMpan6oCKiNl7dpHBcymvoLJjScbouHvYDeE0dbaJcMuq0WRoEV0h4Kd4MNRLUJhDTwE8eVGqA1QzQjp7JLppeXFVXI7Ztgj6ZLf2Zcd/V cloudbreak
" >> /home/ec2-user/.ssh/authorized_keys
echo "#tmpssh_end" >> /home/ec2-user/.ssh/authorized_keys
}
get_ip() {
ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'
}
fix_hostname() {
if grep -q $(get_ip) /etc/hosts ;then
sed -i "/$(get_ip)/d" /etc/hosts
else
echo OK
fi
}
extend_rootfs() {
# Usable on GCP, does not harm anywhere else
root_fs_device=$(mount | grep ' / ' | cut -d' ' -f 1 | sed s/1//g)
growpart $root_fs_device 1
xfs_growfs /
}
format_disks() {
mkdir /hadoopfs
for (( i=1; i<=24; i++ )); do
LABEL=$(printf "\x$(printf %x $((START_LABEL+i)))")
DEVICE=/dev/${PLATFORM_DISK_PREFIX}${LABEL}
if [ -e $DEVICE ]; then
MOUNTPOINT=$(grep $DEVICE /etc/fstab | tr -s ' \t' ' ' | cut -d' ' -f 2)
if [ -n "$MOUNTPOINT" ]; then
umount "$MOUNTPOINT"
sed -i "\|^$DEVICE|d" /etc/fstab
fi
mkfs -E lazy_itable_init=1 -O uninit_bg -F -t ext4 $DEVICE
mkdir /hadoopfs/fs${i}
echo $DEVICE /hadoopfs/fs${i} ext4 defaults,noatime 0 2 >> /etc/fstab
mount /hadoopfs/fs${i}
fi
done
cd /hadoopfs/fs1 && mkdir logs logs/ambari-server logs/ambari-agent logs/consul-watch
}
reload_sysconf() {
sysctl -p
}
main() {
reload_sysconf
if [[ "$1" == "::" ]]; then
shift
eval "$@"
elif [ ! -f "/var/cb-init-executed" ]; then
setup_tmp_ssh
extend_rootfs
format_disks
fix_hostname
touch /var/cb-init-executed
echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/cb-init-executed
fi
}
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
core_user_data_config:
type: OS::Heat::SoftwareConfig
properties:
config: |
#!/bin/bash
set -x
START_LABEL=97
PLATFORM_DISK_PREFIX=vd
get_ip() {
ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'
}
fix_hostname() {
if grep -q $(get_ip) /etc/hosts ;then
sed -i "/$(get_ip)/d" /etc/hosts
else
echo OK
fi
}
extend_rootfs() {
# Usable on GCP, does not harm anywhere else
root_fs_device=$(mount | grep ' / ' | cut -d' ' -f 1 | sed s/1//g)
growpart $root_fs_device 1
xfs_growfs /
}
format_disks() {
mkdir /hadoopfs
for (( i=1; i<=24; i++ )); do
LABEL=$(printf "\x$(printf %x $((START_LABEL+i)))")
DEVICE=/dev/${PLATFORM_DISK_PREFIX}${LABEL}
if [ -e $DEVICE ]; then
MOUNTPOINT=$(grep $DEVICE /etc/fstab | tr -s ' \t' ' ' | cut -d' ' -f 2)
if [ -n "$MOUNTPOINT" ]; then
umount "$MOUNTPOINT"
sed -i "\|^$DEVICE|d" /etc/fstab
fi
mkfs -E lazy_itable_init=1 -O uninit_bg -F -t ext4 $DEVICE
mkdir /hadoopfs/fs${i}
echo $DEVICE /hadoopfs/fs${i} ext4 defaults,noatime 0 2 >> /etc/fstab
mount /hadoopfs/fs${i}
fi
done
cd /hadoopfs/fs1 && mkdir logs logs/ambari-server logs/ambari-agent logs/consul-watch
}
reload_sysconf() {
sysctl -p
}
main() {
reload_sysconf
if [[ "$1" == "::" ]]; then
shift
eval "$@"
elif [ ! -f "/var/cb-init-executed" ]; then
extend_rootfs
format_disks
fix_hostname
touch /var/cb-init-executed
echo $(date +%Y-%m-%d:%H:%M:%S) >> /var/cb-init-executed
fi
}
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
ambari_hostgroupmaster2_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"host_group_master_2","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_hostgroupmaster2_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: core_user_data_config }
ambari_app_port_hostgroupmaster2_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_hostgroupmaster2_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_hostgroupmaster2_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_hostgroupmaster2_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_hostgroupmaster2_0_0 }
ambari_server_floatingip_hostgroupmaster2_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_hostgroupmaster2_0 }
ambari_cbgateway_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"cbgateway","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_cbgateway_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: gw_user_data_config }
ambari_app_port_cbgateway_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_cbgateway_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_cbgateway_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_cbgateway_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_cbgateway_0_0 }
ambari_server_floatingip_cbgateway_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_cbgateway_0 }
ambari_hostgroupmaster1_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"host_group_master_1","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_hostgroupmaster1_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: core_user_data_config }
ambari_app_port_hostgroupmaster1_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_hostgroupmaster1_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_hostgroupmaster1_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_hostgroupmaster1_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_hostgroupmaster1_0_0 }
ambari_server_floatingip_hostgroupmaster1_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_hostgroupmaster1_0 }
ambari_hostgroupslave1_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"host_group_slave_1","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_hostgroupslave1_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: core_user_data_config }
ambari_app_port_hostgroupslave1_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_hostgroupslave1_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_hostgroupslave1_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_hostgroupslave1_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_hostgroupslave1_0_0 }
ambari_server_floatingip_hostgroupslave1_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_hostgroupslave1_0 }
ambari_hostgroupclient1_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"host_group_client_1","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_hostgroupclient1_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: core_user_data_config }
ambari_app_port_hostgroupclient1_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_hostgroupclient1_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_hostgroupclient1_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_hostgroupclient1_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_hostgroupclient1_0_0 }
ambari_server_floatingip_hostgroupclient1_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_hostgroupclient1_0 }
ambari_hostgroupmaster3_0:
type: OS::Nova::Server
properties:
image: { get_param: image_id }
flavor: mmem-4vcpu
key_name: { get_param: key_name }
metadata: {"cb_instance_group_name":"host_group_master_3","cb_instance_private_id":"0"}
networks:
- port: { get_resource: ambari_app_port_hostgroupmaster3_0 }
user_data_format: SOFTWARE_CONFIG
user_data: { get_resource: core_user_data_config }
ambari_app_port_hostgroupmaster3_0:
type: OS::Neutron::Port
properties:
network_id: { get_resource: app_network }
replacement_policy: AUTO
fixed_ips:
- subnet_id: { get_resource: app_subnet }
security_groups: [ { get_resource: server_security_group } ]
ambari_volume_hostgroupmaster3_0_0:
type: OS::Cinder::Volume
properties:
name: hdfs-volume
size: 40
ambari_volume_attach_hostgroupmaster3_0_0:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: ambari_hostgroupmaster3_0 }
mountpoint: /dev/vdb
volume_id: { get_resource: ambari_volume_hostgroupmaster3_0_0 }
ambari_server_floatingip_hostgroupmaster3_0:
type: OS::Neutron::FloatingIP
properties:
floating_network_id: { get_param: public_net_id }
port_id: { get_resource: ambari_app_port_hostgroupmaster3_0 }
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
description: Cloudbreak security group
name: cb-sec-group_cluster12345
rules: [
{remote_ip_prefix: 0.0.0.0/0,
protocol: tcp,
port_range_min: 22,
port_range_max: 22},
{remote_ip_prefix: 0.0.0.0/0,
protocol: tcp,
port_range_min: 443,
port_range_max: 443},
{remote_ip_prefix: { get_param: app_net_cidr },
protocol: tcp,
port_range_min: 1,
port_range_max: 65535},
{remote_ip_prefix: { get_param: app_net_cidr },
protocol: udp,
port_range_min: 1,
port_range_max: 65535},
{remote_ip_prefix: { get_param: app_net_cidr },
protocol: icmp}]
outputs:
instance_uuid_hostgroupmaster2_0:
value: { get_attr: [ambari_hostgroupmaster2_0, show, id] }
instance_uuid_cbgateway_0:
value: { get_attr: [ambari_cbgateway_0, show, id] }
instance_uuid_hostgroupmaster1_0:
value: { get_attr: [ambari_hostgroupmaster1_0, show, id] }
instance_uuid_hostgroupslave1_0:
value: { get_attr: [ambari_hostgroupslave1_0, show, id] }
instance_uuid_hostgroupclient1_0:
value: { get_attr: [ambari_hostgroupclient1_0, show, id] }
instance_uuid_hostgroupmaster3_0:
value: { get_attr: [ambari_hostgroupmaster3_0, show, id] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment