ab47c46e by Volodymyr Tsap

initial commit

0 parents
1 # Compiled files
2 *.tfstate
3 *.tfstate.backup
4
5 # Module directory
6 .terraform/
1 # Packer script to build the universal AMI.
2
3 ```
4 # setup your AMS access parameters in ~/.aws
5
6 # build the AMI
7 ./packer-build-ami.sh
8 ```
1 TOMCAT8_USER=tomcat8
2 TOMCAT8_GROUP=tomcat8
3 JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseConcMarkSweepGC"
1 driftfile /var/lib/ntp/ntp.drift
2
3 restrict default nomodify nopeer noquery notrap limited kod
4 restrict -6 default nomodify nopeer noquery notrap limited kod
5 restrict 127.0.0.1
6 restrict -6 ::1
7
8 server 0.amazon.pool.ntp.org iburst
9 server 1.amazon.pool.ntp.org iburst
10 server 2.amazon.pool.ntp.org iburst
11 server 3.amazon.pool.ntp.org iburst
1 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDS2AobPFQwjqYtvMoehWuZzpcWxxrndl0yZWUWlPp9FycejV/WMbaQToi8SbgdW5v8MY1LO1DhQIbGYt3x8Oq3UZ3OsyWLH4uOMIUe8vI/FjlvjoRErIEWag6R1ISq9kcDjECfmFxjbJY6X0y1xtOYlJXORfVFQsCthgehUscnNKMdMtdA/Jd+Oe4OjEtsPuErDClnkSKe1D8H0dRVLU+UVPQw53LZlqZRK0KE5e8MPMDtJyhL21AjrxrfmpsliXi/3d82VsZJxyn2at48OlNRqJ+IL/6rLP9O2b1pRgDBgC4GME9hVrlbVcXxc4OAAPOfqCuchk7bw61aivrJByVee23GtZkNt3xhHYuvuMM6ose+boo2BydIcg5ZvRgiNcZrUKS/j5bH6Fhpxx/rr3r1B8rBaL2DruXUrJ3X8GuORbMro9tZpHaU6E5Sq5rPYLNL+XySAaK4iyIuytFhcoZDDzhtywNUKPyCqQOEkeZp8OsXMs5E9lkJ5ffDzEjCl299yEb9Vgig35xkmljIXb7FxWLHuAKx5InGlQqo7pty0oRz5VGxcAQ+EAKr/7VlcXOO/mZx4/7BNblEO68M3xpCeXGyyJzrpLwSmmvDF76Y8D1ulYtq2Z72+cKiiibWjLWDaTidKY+WjaeL8HI+9AaWz8lW8vL+Ulyre1Z8o+4w5w== bohdaq@gmail.com
1 # This file is managed by Ansible, don't make changes here - they will be overwritten.
2
3 # Source global definitions
4 if [ -f /etc/bashrc ]; then
5 . /etc/bashrc
6 fi
7
8 export EDITOR=$(which vim)
9 export PAGER=$(which less)
10 export LESS="-R"
11 export GREP_COLORS='ms=01;31:mc=01;31:sl=:cx=:fn=0;49;92:ln=32:bn=32:se=36'
12 export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin
13 export LANG=en_US.utf8
14 export LC_ALL=en_US.utf8
15 export HISTFILESIZE=10000
16 export HISTSIZE=10000
17 export HISTCONTROL=erasedups
18 export HISTIGNORE="&:ls:screen *:top:htop"
19 export HISTTIMEFORMAT="%t%d.%m.%y %H:%M:%S%t"
20
21 shopt -s histappend
22
23 complete -cf man
24 complete -cf nice
25 complete -cf ionice
26
27
28 alias c='clear'
29 alias s='set -o vi'
30 alias h='htop'
31 alias t='top'
32 alias m='mysql -e "SHOW FULL PROCESSLIST;"'
33 alias mf='mysql -e "SHOW FULL PROCESSLIST; show engine innodb status\G"'
34 alias d='dirs -v'
35 alias pu="pushd"
36 alias po="popd"
37 alias i='ip addr'
38 alias v='vim "+colorscheme elflord" "+syntax on"'
39 alias p='pwd'
40 alias ru="export INPUTRC=/root/.inputrc.yamato"
41 alias e='egrep'
42 alias config_show="e -v '(^#|^$|^[[:space:]]+#)'"
43 alias sy='/bin/systemctl'
44
45 # http://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
46 # for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less'
47 alias show_swap_usage='for file in /proc/*/status ; do awk '\''/VmSwap|Name/{printf $2 " " $3}END{ print ""}'\'' $file; done | sort -k 2 -n -r | less'
48
49 # notify shortcut
50 jobdone() {
51 echo "DONE!" | mail -s "$(hostname): ${1:-Your job is done} [NOSR]" ${2:-yamato@shalb.com}
52 }
53
54 # count size of directories
55 dudu() {
56 ionice -c 3 nice -n 20 du -x -h --max-depth="$1" "$2" > /tmp/du
57 sort -h /tmp/du > /tmp/du_sorted
58 jobdone
59 }
60
61 # strace wrapper
62 str() {
63 strace -vyCTrf -s 1024 -o /tmp/strace.log -p "$1"
64 }
65
66
67 # custom aliases
1 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCke3hZ6iQJS3JU2KoPbfVjHkIlHnKMpVBQPDbzAY+RIbRXjdo2AExT1Ke9PTvEUMwktctZuwZbaX2h49fFVgKCcXcJoPuOJXiChaa5u0D5BxkwFaiATZDk8/dGnyJufqfydgHWdzG+QOXq38MTvr14b8xIJ+d/RuGt+jpxcOdaBbQPLSsy63ePwfX5QlhWNiLfLXAoQ2vFp+aY7H8XgFch3rWY/X4RBOpIY4CYpZZZRRnfq+Ys0qwAjB4pPRZe6DKjvaJEHJp+d77yNGXOhQYRexMWvlflU56mC7Qa5KRch4kj245EKEmTPofo9rA7GwohEQys69p/bxg6pZjNGUbL dracut@auth.shalb.com
2 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCi6UIVruH0CfKewYlSjA7oR6gjahZrkJ+k/0cj46nvYrORVcds2cijZPT34ACWkvXV8oYvXGWmvlGXV5H1sD0356zpjhRnGo6j4UZVS6KYX5HwObdZ6H/i+A9knEyXxOCyo6p4VeJIYGhVYcQT4GDAkxb8WXHVP0Ax/kUqrKx0a2tK9JjGkuLbufQc3yWhqcfZSVRU2a+M8f8EUmGLOc2VEi2mGoxVgikrelJ0uIGjLn63L6trrsbvasoBuILeXOAO1xICwtYFek/MexQ179NKqQ1Wx/+9Yx4Xc63MB0vR7kde6wxx2Auzp7CjJBFcSTz0TXSRsvF3mnUUoUrclNkr voa@auth.shalb.com
3 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1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Dvon0eb38jjapV6nJgSH1BASBt8l64LA6SGUSAOENCv3 arti@auth.shalb.com
6 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9+eRDg5IArS8N0KVcOqP64ozZvbZQDHOq7BFVwDsoWxMGLlxhgdx/55cpOUXan+cnHPpRT2dGuGftr624SYV60TwrhGHukN0Kc4l0FtSvhjfLi1JN+3hSMdICAMWW7jYoSVNfQ+RAicRfEhjoCrcl0SmEYFlDT9OjiOLG9PxehKzgiJSAdCYoHSvirYM5vJJ7eYpeZkkECEtbX0xNzf9sPGKAgiRdD3UB3RTtoftsdqf6/ew6RLcZ7DVT89v6fXhWEqomWHZoHJf3sPeKVQgqgh+z8fJsea/Lkmc03pZmMNW2B8+xtbwW7/rmwU3o+44KXVqQ1kP9WKCgihD/RJiv logka@auth.shalb.com
7 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfozZljVqfwmebNPIU7t+A0+UkTArd5pBvlZgSHk8ojCWRfTHV67Jggg5Kk8SkIRa1mT6/4Adl5rpyHWZsL+ND0hzWjpFG4A4V6dHN1/EFyLfx0bIck7pzBjq0IMHR1cZ+RjzyrhxpIkATtIvipZGy1zdyPQEyXKKx2kWvUlAUgqkpE9XZPazk3iYupajpXuegZOckuCgNPVjw/qxwWi5c6LrUgTHWBA+HbhShXXus6ogVC9X1xcon4wFoxveHfZemN5X09BP38pAyzIJAskCYqGDfTehI6cSc7EEycWnEx2B0vUKEVAcTyRXxjSPOk2vil+pTAdhaUfRAqAqeYiPL root@rundeck.shalb.com
1 #!/bin/bash
2
3 java_config_file=/usr/share/tomcat8/bin/setenv.sh
4 java_additional_params=$@
5
6 cat > ${java_config_file} << EOF
7 JAVA_OPTS="\$JAVA_OPTS ${java_additional_params}"
8 EOF
1 #!/bin/bash
2 packer build xp-ami-packer.json
1 #!/bin/bash
2
3 _apt_opts="sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold"
4 _apt_install_cmd="${_apt_opts} install"
5 _apt_upgrade_cmd="${_apt_opts} dist-upgrade"
6
7 ssh_auth_key_file="/root/.ssh/authorized_keys"
8 ssh_root_pubkey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCi6UIVruH0CfKewYlSjA7oR6gjahZrkJ+k/0cj46nvYrORVcds2cijZPT34ACWkvXV8oYvXGWmvlGXV5H1sD0356zpjhRnGo6j4UZVS6KYX5HwObdZ6H/i+A9knEyXxOCyo6p4VeJIYGhVYcQT4GDAkxb8WXHVP0Ax/kUqrKx0a2tK9JjGkuLbufQc3yWhqcfZSVRU2a+M8f8EUmGLOc2VEi2mGoxVgikrelJ0uIGjLn63L6trrsbvasoBuILeXOAO1xICwtYFek/MexQ179NKqQ1Wx/+9Yx4Xc63MB0vR7kde6wxx2Auzp7CjJBFcSTz0TXSRsvF3mnUUoUrclNkr voa@shalb.com"
9
10 # deploy configs (preinstall)
11 sudo chown -R root:root /tmp/configs_preinstall
12 sudo rsync -av /tmp/configs_preinstall/ /
13
14 # add ssh pubkey for root user
15 sudo sed -i "\$a${ssh_root_pubkey}" "${ssh_auth_key_file}"
16
17 # upgrade all packages
18 sudo apt-get update
19 ${_apt_upgrade_cmd}
20
21 # install additional soft
22 ${_apt_install_cmd} htop atop mtr sysstat tcptraceroute nload unzip iotop apt-file unzip mysql-client
23
24 # Ntp
25 ${_apt_install_cmd} ntp
26 sudo systemctl enable ntp
27 sudo systemctl start ntp
28
29 # Postfix
30 echo "postfix postfix/mailname string example.com" | sudo debconf-set-selections
31 echo "postfix postfix/main_mailer_type string 'Internet Site'" | sudo debconf-set-selections
32 ${_apt_install_cmd} postfix mailutils mutt
33
34 # Oracle Java
35 sudo apt-add-repository -y ppa:webupd8team/java
36 sudo apt-get update
37 echo 'oracle-java8-installer shared/accepted-oracle-license-v1-1 select true' | sudo /usr/bin/debconf-set-selections
38 ${_apt_install_cmd} oracle-java8-installer
39
40 # Tomcat
41 #${_apt_install_cmd} tomcat8 haveged
42 #sudo rm -rf /var/lib/tomcat8/webapps/ROOT/
43
44 # clear logs
45 sudo rm -rf /var/log/*/*
46 # Apache2
47 #${_apt_install_cmd} apache2
48
49 # Install Play Framework
50 cd /opt
51 sudo wget https://downloads.typesafe.com/play/1.5.0/play-1.5.0.zip
52 sudo unzip play-1.5.0.zip
53 sudo ln -s /opt/play-1.5.0/play /usr/local/bin/play
54
55 # deploy configs (post-install)
56 sudo chown -R root:root /tmp/configs
57 sudo rsync -av /tmp/configs/ /
58 sudo chown -R ubuntu:ubuntu /home/ubuntu
1 {
2 "variables": {
3 "aws_access_key": "",
4 "aws_secret_key": ""
5 },
6 "_comment": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
7 "builders": [{
8 "type": "amazon-ebs",
9 "access_key": "{{user `aws_access_key`}}",
10 "secret_key": "{{user `aws_secret_key`}}",
11 "region": "eu-central-1",
12 "source_ami_filter": {
13 "filters": {
14 "virtualization-type": "hvm",
15 "name": "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170721",
16 "root-device-type": "ebs"
17 },
18 "most_recent": true
19 },
20 "subnet_id": "subnet-f1e92d8a",
21 "instance_type": "t2.micro",
22 "ssh_username": "ubuntu",
23 "ami_name": "xpdays-ami {{timestamp}}"
24 }],
25 "provisioners": [
26 {
27 "type": "file",
28 "source": "./configs",
29 "destination": "/tmp/"
30 },
31 {
32 "type": "shell",
33 "script": "provision-ami.sh"
34 }
35 ]
36 }
1 ## Define provider
2 provider "aws" {
3 region = "eu-central-1"
4 }
5
6 ## Get instance AMI
7 data "aws_ami" "ubuntu" {
8 most_recent = true
9 filter {
10 name = "name"
11 values = ["ubuntu/images/hvm-ssd/ubuntu-*-16.04-amd64-server-*"]
12 }
13 }
14 # Define the instance
15 resource "aws_instance" "test-ec2instance" {
16 ami = "${data.aws_ami.ubuntu.id}"
17 instance_type = "t2.micro"
18 }
1 ## Get instance AMI
2 data "aws_ami" "ubuntu" {
3 most_recent = true
4 filter {
5 name = "name"
6 values = ["ubuntu/images/hvm-ssd/ubuntu-*-16.04-amd64-server-*"]
7 }
8 }
1 ## Define provider
2 provider "aws" {
3 region = "${var.region}"
4 }
5
6 # Define the instance
7 resource "aws_instance" "test-ec2instance" {
8 ami = "${data.aws_ami.ubuntu.id}"
9 vpc_security_group_ids = [ "${var.vpc_security_group_ids[1]}" ]
10 instance_type = "${lookup(var.instance_type, var.environment)}"
11 count = 1
12 }
1 # String
2 region = "eu-central-1"
3
4 # List
5 vpc_security_group_ids = [ "sg-84e649ed", "sg-90ea45fa" ]
6
7 # Map
8 instance_type = {
9 production = "t2.micro"
10 development = "m3.medium"
11 }
12
13 # Map of Lists
14 vpc_security_group_ids_map = {
15 eu-central-1 = [ "sg-84e649ed", "sg-90ea45fa" ]
16 eu-west-1 = [ "sg-1d4ab664", "sg-90ea45fa" ]
17 }
18
1 variable "region" {
2 type = "string"
3 default = "eu-central-1"
4 description = "The AWS region"
5 }
6
7 variable "environment" {
8 description = "The Environment Type"
9 default = "production"
10 }
11
12 variable "vpc_security_group_ids" {
13 type = "list"
14 }
15
16 variable "instance_type" {
17 type = "map"
18 default = {}
19 }
20
21 variable "vpc_security_group_ids_map" {
22 type = "map"
23 default = {}
24 }
1 ## Get instance AMI
2 data "aws_ami" "xpdays-ami" {
3 most_recent = true
4 filter {
5 name = "name"
6 values = ["xpdays-ami*"]
7 }
8 }
1 ## Define provider
2 provider "aws" {
3 region = "${var.region}"
4 }
5
6 # Define the instance
7 resource "aws_instance" "xpdays-instance" {
8 ami = "${data.aws_ami.xpdays-ami.id}"
9 vpc_security_group_ids = [ "${var.vpc_security_group_ids}" ]
10 instance_type = "${lookup(var.instance_type, var.environment)}"
11 user_data = <<EOF
12 #!/bin/bash
13 hostname xpdays${count.index + 1} && hostname > /etc/hostname
14 echo "127.0.0.1 localhost xpdays1" > /etc/hosts
15 cd /home/ubuntu
16 git clone https://bitbucket.org/bohdaq/wisehands.me.git
17 cd /home/ubuntu/wisehands.me/ && play deps
18 mkdir -p /home/ubuntu/wisehands.me/modules/guice-1.2
19 cd /home/ubuntu/wisehands.me/modules/guice-1.2
20 wget https://www.playframework.com/modules/guice-1.2.zip
21 unzip guice-1.2.zip
22 sed -i 's/mysql-database-endpoint/${aws_db_instance.db-instance.username}:${aws_db_instance.db-instance.password}@${aws_db_instance.db-instance.endpoint}\/${aws_db_instance.db-instance.name}/g' /home/ubuntu/wisehands.me/conf/application.conf
23 cd /home/ubuntu/wisehands.me/ && play run
24 EOF
25 tags {
26 Name = "xpdays${count.index + 1}"
27 }
28
29 count = 1
30 }
31
32 ## Print Output
33 output "xpdays_instance_public_ip" {
34 value = "${join(",",aws_instance.xpdays-instance.*.public_ip)}"
35
36 }
37
1 resource "aws_db_subnet_group" "default_db_subnet_group" {
2 name = "main"
3 subnet_ids = ["${var.default_db_subnet_group_subnet_ids[var.region]}"]
4 tags {
5 Name = "Default DB subnet group"
6 }
7 }
8
9 resource "aws_db_instance" "db-instance" {
10 allocated_storage = 10
11 storage_type = "gp2"
12 engine = "mysql"
13 engine_version = "5.7.17"
14 instance_class = "db.t2.micro"
15 name = "wisehandsdb"
16 username = "root"
17 password = "53N4CsNmQrxh2"
18 db_subnet_group_name = "${aws_db_subnet_group.default_db_subnet_group.id}"
19 final_snapshot_identifier = "snapshot-defaultdbinstance${count.index + 1}"
20 skip_final_snapshot = true
21 publicly_accessible = true
22 tags {
23 key = "Name"
24 value = "default-db-instance${count.index + 1}-${var.environment}"
25 }
26 }
27
28 output "database_endpoint" {
29 value = "${aws_db_instance.db-instance.username}:${aws_db_instance.db-instance.password}@${aws_db_instance.db-instance.endpoint}/${aws_db_instance.db-instance.name}"
30 }
1 # String
2 region = "eu-central-1"
3
4 # List
5 vpc_security_group_ids = [ "sg-84e649ed", "sg-90ea45fa" ]
6
7 # Map
8 instance_type = {
9 production = "t2.micro"
10 development = "m3.medium"
11 }
12
13 # Map of Lists
14 default_db_subnet_group_subnet_ids = {
15 eu-central-1 = [ "subnet-f1e92d8a", "subnet-304b7f7a" ]
16 eu-west-1 = [ "subnet-f1e92d8a", "subnet-304b7f7a" ]
17 }
18
1 variable "region" {
2 type = "string"
3 default = "eu-central-1"
4 description = "The AWS region"
5 }
6
7 variable "environment" {
8 description = "The Environment Type"
9 default = "production"
10 }
11
12 variable "vpc_security_group_ids" {
13 type = "list"
14 }
15
16 variable "instance_type" {
17 type = "map"
18 default = {}
19 }
20
21 variable "default_db_subnet_group_subnet_ids" {
22 type = "map"
23 default = {}
24 }