-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from Kushmaro/terraform-ansible-example
Updated example to install ece using ansible
- Loading branch information
Showing
10 changed files
with
259 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Cloud Enterprise/Getting Started Examples/aws/terraform/ansible-install.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Short form: set -u | ||
set -o nounset | ||
# Short form: set -e | ||
set -o errexit | ||
|
||
# Print a helpful message if a pipeline with non-zero exit code causes the | ||
# script to exit as described above. | ||
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR | ||
|
||
# Allow the above trap be inherited by all functions in the script. | ||
# | ||
# Short form: set -E | ||
set -o errtrace | ||
|
||
# Return value of a pipeline is the value of the last (rightmost) command to | ||
# exit with a non-zero status, or zero if all commands in the pipeline exit | ||
# successfully. | ||
set -o pipefail | ||
|
||
# Set $IFS to only newline and tab. | ||
# | ||
# http://www.dwheeler.com/essays/filenames-in-shell.html | ||
IFS=$'\n\t' | ||
|
||
############################################################################### | ||
# Program Functions | ||
############################################################################### | ||
|
||
_verify_ansible() { | ||
if [ -x "$(command -v ansible-galaxy)" ]; then | ||
# install role | ||
ansible-galaxy install git+https://github.com/elastic/ansible-elastic-cloud-enterprise.git | ||
else | ||
echo "ERROR: Ansible isn't installed on this machine, aborting ece installation" | ||
exit 1 | ||
fi | ||
} | ||
|
||
_write_ansible_playbook() { | ||
cat << PLAYBOOK > ./ece.yml | ||
--- | ||
- hosts: primary | ||
gather_facts: true | ||
roles: | ||
- ansible-elastic-cloud-enterprise | ||
vars: | ||
ece_primary: true | ||
ece_version: ${ece-version} | ||
- hosts: secondary | ||
gather_facts: true | ||
roles: | ||
- ansible-elastic-cloud-enterprise | ||
vars: | ||
ece_roles: [director, coordinator, proxy, allocator] | ||
ece_version: ${ece-version} | ||
- hosts: tertiary | ||
gather_facts: true | ||
roles: | ||
- ansible-elastic-cloud-enterprise | ||
vars: | ||
ece_roles: [director, coordinator, proxy, allocator] | ||
ece_version: ${ece-version} | ||
PLAYBOOK | ||
} | ||
|
||
_write_ansible_hosts() { | ||
cat << HOSTS_FILE > ./hosts | ||
[primary] | ||
${ece-server0} | ||
[primary:vars] | ||
availability_zone=${ece-server0-zone} | ||
[secondary] | ||
${ece-server1} | ||
[secondary:vars] | ||
availability_zone=${ece-server1-zone} | ||
[tertiary] | ||
${ece-server2} | ||
[tertiary:vars] | ||
availability_zone=${ece-server2-zone} | ||
[aws:children] | ||
primary | ||
secondary | ||
tertiary | ||
[aws:vars] | ||
ansible_ssh_private_key_file=${key} | ||
ansible_user=${user} | ||
ansible_become=yes | ||
device_name=${device} | ||
HOSTS_FILE | ||
} | ||
|
||
_run_ansible() { | ||
export ANSIBLE_HOST_KEY_CHECKING=False | ||
ansible-playbook -i hosts ece.yml | ||
} | ||
|
||
############################################################################### | ||
# Main | ||
############################################################################### | ||
|
||
# _main() | ||
# | ||
# Usage: | ||
# _main [<options>] [<arguments>] | ||
# | ||
# Description: | ||
# Entry point for the program, handling basic option parsing and dispatching. | ||
_main() { | ||
_verify_ansible | ||
_write_ansible_playbook | ||
_write_ansible_hosts | ||
sleep 30 | ||
_run_ansible | ||
} | ||
|
||
# Call `_main` after everything has been defined. | ||
_main "$@" |
55 changes: 0 additions & 55 deletions
55
Cloud Enterprise/Getting Started Examples/aws/terraform/install.sh
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
Cloud Enterprise/Getting Started Examples/aws/terraform/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Initiate ece installation through ansible playbook | ||
resource "null_resource" "run-ansible" { | ||
provisioner "local-exec" { | ||
command = "${data.template_file.ansible-install.rendered}" | ||
} | ||
} | ||
|
||
output "ece-instances" { | ||
description = "The public dns of created server instances." | ||
value = ["${aws_instance.server.*.public_dns}"] | ||
} | ||
|
||
output "installed-ece-url" { | ||
value = "${format("https://%s:12443","${aws_instance.server.0.public_dns}")}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,4 @@ resource "aws_security_group" "internal" { | |
to_port = 0 | ||
self = true | ||
} | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
Cloud Enterprise/Getting Started Examples/aws/terraform/provider.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
provider "aws" { | ||
region = "${var.region}" | ||
profile = "${var.profile}" | ||
version = "1.3.0" | ||
} | ||
|
||
provider "template" { | ||
version = "1.0.0" | ||
} | ||
|
||
terraform { | ||
required_version = "0.11.1" | ||
} | ||
required_version = "0.11.14" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ profile = "YOUR-AWS-PROFILE" | |
|
||
trusted_network = "YOUR-IP/32" | ||
|
||
name = "YOUR-NAME" | ||
name = "YOUR-NAME" |
22 changes: 0 additions & 22 deletions
22
Cloud Enterprise/Getting Started Examples/aws/terraform/user_data.sh
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.