AWSTemplateFormatVersion: 2010-09-09 Description: Creates Cassandra clusternode(s) in ASG (qs-1r0baum2g) Parameters: OSSVersion: AllowedValues: # - 3.11.5 # - 3.11.6 - 4.0 Default: 4.0 Description: "Apache Cassandra version to install." Type: String ClusterName: Description: Name of the Cassandra Cluster. Type: String Default: Cassandra-Cluster CreateClusterWithPublicIP: Description: "Whether to create the Cassandra Cluster nodes in public subnet" Type: String Default: "false" AllowedValues: - "false" - "true" DatacenterName: Description: Name of the Cassandra Datacenter. Type: String Default: OSS-dc0 InstanceType: Description: EC2 instance type Type: String Default: m4.large AllowedValues: - t2.medium - t2.large - t2.xlarge - t2.2xlarge - m4.large - m4.xlarge - m4.2xlarge - m4.4xlarge - m4.10xlarge - m4.16xlarge - c4.large - c4.xlarge - c4.2xlarge - c4.4xlarge - c4.8xlarge - r4.large - r4.xlarge - r4.2xlarge - r4.4xlarge - r4.8xlarge - r4.16xlarge ConstraintDescription: must be a valid EC2 instance type. KeyPairName: Type: 'AWS::EC2::KeyPair::KeyName' ConstraintDescription: Name of an existing EC2 KeyPair. Subnet1ID: Description: Subnet Id 1 Type: 'AWS::EC2::Subnet::Id' Subnet2ID: Description: Subnet Id 2 Type: 'AWS::EC2::Subnet::Id' Subnet3ID: Description: Subnet Id 3 Type: 'AWS::EC2::Subnet::Id' ClusterSize: Description: "Number of Cassandra nodes to create." Type: String Default: 3 AllowedValues: - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - 29 - 30 - 31 - 32 SecGroup: Description: "Security Group ID." Type: 'List' SeedNodeIps: Description: "csv IPs of the seedsnodes." Type: String VolumeSize: Type: Number Description: "EBS volume size of the Cassandra Cluster Nodes in GB" Default: 512 Mappings: ClusterSizeMap: "4": Value: "1" "5": Value: "2" "6": Value: "3" "7": Value: "4" "8": Value: "5" "9": Value: "6" "10": Value: "7" "11": Value: "8" "12": Value: "9" "13": Value: "10" "14": Value: "11" "15": Value: "12" "16": Value: "13" "17": Value: "14" "18": Value: "15" "19": Value: "16" "20": Value: "17" "21": Value: "18" "22": Value: "19" "23": Value: "20" "24": Value: "21" "25": Value: "22" "26": Value: "23" "27": Value: "24" "28": Value: "25" "29": Value: "26" "30": Value: "27" "31": Value: "28" "32": Value: "29" AWSAMIRegionMap: ap-northeast-1: US1804HVM: ami-0278fe6949f6b1a06 ap-northeast-2: US1804HVM: ami-00edfb46b107f643c ap-south-1: US1804HVM: ami-0b44050b2d893d5f7 ap-southeast-1: US1804HVM: ami-0f7719e8b7ba25c61 ap-southeast-2: US1804HVM: ami-04fcc97b5f6edcd89 ca-central-1: US1804HVM: ami-0edd51cc29813e254 eu-central-1: US1804HVM: ami-0e342d72b12109f91 me-south-1: US1804HVM: ami-051274f257aba97f9 ap-east-1: US1804HVM: ami-c790d6b6 eu-north-1: US1804HVM: ami-050981837962d44ac eu-west-1: US1804HVM: ami-0701e7be9b2a77600 eu-west-2: US1804HVM: ami-0eb89db7593b5d434 eu-west-3: US1804HVM: ami-08c757228751c5335 sa-east-1: US1804HVM: ami-077d5d3682940b34a us-east-1: US1804HVM: ami-085925f297f89fce1 us-gov-west-1: US1804HVM: ami-adecdbcc us-gov-east-1: US1804HVM: ami-c29975b3 us-east-2: US1804HVM: ami-07c1207a9d40bc3bd us-west-1: US1804HVM: ami-0f56279347d2fa43e us-west-2: US1804HVM: ami-003634241a8fcdec0 cn-north-1: US1804HVM: ami-0071f6f4df15863cc cn-northwest-1: US1804HVM: ami-0a22b8776bb32836b Resources: ClusterNodeGroup: Type: 'AWS::AutoScaling::AutoScalingGroup' Properties: # AutoScalingGroupName: CassandraClusterASG VPCZoneIdentifier: - !Ref Subnet3ID - !Ref Subnet1ID - !Ref Subnet2ID LaunchConfigurationName: !Ref ClusterNodeLaunchConfig MinSize: !FindInMap - ClusterSizeMap - !Ref ClusterSize - Value MaxSize: !FindInMap - ClusterSizeMap - !Ref ClusterSize - Value Tags: - Key: Name PropagateAtLaunch: true Value: Cassandra_node_ASG CreationPolicy: ResourceSignal: Timeout: PT10M Count: '1' UpdatePolicy: AutoScalingRollingUpdate: MinInstancesInService: 1 MaxBatchSize: 1 PauseTime: PT10M WaitOnResourceSignals: true ClusterNodeLaunchConfig: Type: 'AWS::AutoScaling::LaunchConfiguration' Metadata: 'AWS::CloudFormation::Init': configSets: cs_install: - install_and_enable_cfn_hup - install_cassandra - post_install install_and_enable_cfn_hup: files: /etc/cfn/cfn-hup.conf: content: !Join - '' - - | [main] - stack= - !Ref 'AWS::StackId' - |+ - region= - !Ref 'AWS::Region' - |+ mode: '000400' owner: root group: root /etc/cfn/hooks.d/cfn-auto-reloader.conf: content: !Join - '' - - | [cfn-auto-reloader-hook] - | triggers=post.update - > path=Resources.ClusterNodeLaunchConfig.Metadata.AWS::CloudFormation::Init - 'action=/usr/local/bin/cfn-init -v ' - ' --stack ' - !Ref 'AWS::StackName' - ' --resource ClusterNodeLaunchConfig ' - ' --configsets cs_install ' - ' --region ' - !Ref 'AWS::Region' - |+ - | runas=root /lib/systemd/system/cfn-hup.service: content: !Join - '' - - | [Unit] - |+ Description=cfn-hup daemon - | [Service] - | Type=simple - | ExecStart=/usr/local/bin/cfn-hup - |+ Restart=always - | [Install] - WantedBy=multi-user.target commands: 01enable_cfn_hup: command: systemctl enable cfn-hup.service 02start_cfn_hup: command: systemctl start cfn-hup.service install_cassandra: sources: /home/ubuntu: https://datastax-public.s3.amazonaws.com/aws-qs-oss/oss.tar commands: 00_install_ansible: command: | sudo apt-add-repository ppa:ansible/ansible -y sudo apt update sudo apt-get install openjdk-8-jdk -y sudo apt install ansible -y sudo sed -i '/host_key_checking = False/s/^#*\s*//g' /etc/ansible/ansible.cfg 01_link_directory: command: "ln -s /home/ubuntu /home/cassandra" 02_keygen: command: "/home/cassandra/keygen.sh" 03_run_playbooks: command: "/home/cassandra/playbooks.sh" 04_install_cassandra: command: !Sub | #!/bin/bash -xe echo "---------CreateClusterWithPublicIP----------" echo ${CreateClusterWithPublicIP} if [ "${CreateClusterWithPublicIP}" = "true" ]; then PublicIp=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4/) else PublicIp="" fi echo $PublicIp echo "-----------" ansible-playbook -v -u ubuntu -i /home/cassandra/ansible-hosts.cfg \ --private-key /home/ubuntu/.ssh/id_rsa /home/cassandra/cassandra-install.yml \ --extra-vars "cassandra_version=${OSSVersion} cluster_name=${ClusterName} dc=${DatacenterName} seeds=${SeedNodeIps} publicip=$PublicIp" post_install: commands: 01_post_install_cassandra: command: "touch /tmp/01_post_install_cassandra" Properties: InstanceType: !Ref InstanceType KeyName: !Ref KeyPairName ImageId: !FindInMap - AWSAMIRegionMap - !Ref 'AWS::Region' - US1804HVM BlockDeviceMappings: - DeviceName: /dev/xvdf Ebs: VolumeSize: !Ref VolumeSize VolumeType: gp2 SecurityGroups: !Ref SecGroup UserData: Fn::Base64: !Sub | #!/bin/bash #CFN Signaling fuctions (begin) yum install git -y || apt-get install -y git || zypper -n install git function cfn_fail { cfn-signal -e 1 --stack ${AWS::StackName} --region ${AWS::Region} --resource ClusterNodeGroup exit 1 } function cfn_success { cfn-signal -e 0 --stack ${AWS::StackName} --region ${AWS::Region} --resource ClusterNodeGroup exit 0 } #Load Linux utils until git clone https://github.com/aws-quickstart/quickstart-linux-utilities.git ; do echo "Retrying"; done cd /quickstart-linux-utilities; source quickstart-cfn-tools.source; # Constants # Prep operating systems qs_update-os || qs_err; #qs_bootstrap_pip || qs_err " pip bootstrap failed "; qs_aws-cfn-bootstrap || qs_err " cfn bootstrap failed "; #Run cfn-init configsets cfn-init -v --stack '${AWS::StackName}' --resource ClusterNodeLaunchConfig --configsets cs_install --region ${AWS::Region} || cfn_fail # Signal cfn-init (final check) [ $(qs_status) == 0 ] && cfn_success || cfn_fail