Parcourir la source

working setup

Chris Mague il y a 6 ans
Parent
commit
5b8bc52409
5 fichiers modifiés avec 19 ajouts et 15 suppressions
  1. 7 4
      ansible/playbook.yml
  2. 3 0
      instances.tf
  3. 1 1
      inventory.tpl
  4. 7 9
      provisioning.tf
  5. 1 1
      ssh.tpl

+ 7 - 4
ansible/playbook.yml

@@ -65,12 +65,15 @@
       file:
         state: directory
         path: "/var/tmp/re-download"
-        #    - name: download RE software
-        #      get_url:
-        #        url: https://s3.amazonaws.com/redis-enterprise-software-downloads/5.4.2/redislabs-5.4.2-20-bionic-amd64.tar
-        #        dest: /var/tmp/re-download/redislabs-5.4.2-20-bionic-amd64.tar
     - name: Unarchive software
       unarchive: 
         src: "https://s3.amazonaws.com/redis-enterprise-software-downloads/5.4.2/redislabs-5.4.2-20-bionic-amd64.tar"
         dest: /var/tmp/re-download
         remote_src: yes
+        #    - name: Install the software
+        #      command: "./install.sh -y"
+        #      args:
+        #        chdir: /var/tmp/re-download
+        #        creates: /var/opt/redislabs/log/rlcheck.log
+        #    - name: Ensure redislabs owns the volume
+        #      command: "chown -R redislabs:redislabs /redis"

+ 3 - 0
instances.tf

@@ -15,6 +15,7 @@ resource "aws_ebs_volume" "re-ephemeral" {
   count             = var.data-node-count
   availability_zone = "${element(var.vpc-azs, count.index)}"
   size              = "${var.re-volume-size}"
+  tags              = merge({ Name = "ephemeral-${var.vpc-name}-${count.index}" }, var.common-tags)
 }
 
 resource "aws_volume_attachment" "re-ephemeral" {
@@ -28,6 +29,7 @@ resource "aws_ebs_volume" "re-persistant" {
   count             = var.data-node-count
   availability_zone = "${element(var.vpc-azs, count.index)}"
   size              = "${var.re-volume-size}"
+  tags              = merge({ Name = "persistant-${var.vpc-name}-${count.index}" }, var.common-tags)
 }
 
 resource "aws_volume_attachment" "re-persistant" {
@@ -47,4 +49,5 @@ resource "aws_eip_association" "re-eip-assoc" {
   count         = var.data-node-count
   instance_id   = "${element(aws_instance.re.*.id, count.index)}"
   allocation_id = "${element(aws_eip.re-eip.*.id, count.index)}"
+  depends_on    = ["aws_instance.re", "aws_eip.re-eip"]
 }

+ 1 - 1
inventory.tpl

@@ -1,2 +1,2 @@
 [all]
-${host_ip} ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -F /tmp/${vpc_name}_node_${ncount}.cfg'
+${host_ip} ansible_ssh_common_args='-o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -F /tmp/${vpc_name}_node.cfg'

+ 7 - 9
provisioning.tf

@@ -5,11 +5,11 @@ resource "null_resource" "remote-config" {
   provisioner "remote-exec" {
     connection {
       user        = "ubuntu"
-      host        = "${element(aws_instance.re.*.public_ip, count.index)}"
+      host        = "${element(aws_eip.re-eip.*.public_ip, count.index)}"
       private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
       agent       = true
     }
-    inline = ["sudo apt update && sudo apt install -y python python-pip"]
+    inline = ["sudo apt update > /dev/null  && sudo apt install -y python python-pip > /dev/null"]
   }
   depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc", "null_resource.inventory-setup", "null_resource.ssh-setup"]
 }
@@ -17,23 +17,22 @@ resource "null_resource" "remote-config" {
 ###############################################################################
 # Template Data
 data "template_file" "ansible_inventory" {
-  count = var.data-node-count
+  count    = var.data-node-count
   template = "${file("${path.module}/inventory.tpl")}"
   vars = {
-    host_ip  = "${element(aws_instance.re.*.public_ip, count.index)}"
+    host_ip  = "${element(aws_eip.re-eip.*.public_ip, count.index)}"
     vpc_name = "${var.vpc-name}"
     ncount   = "${count.index}"
   }
+  depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
 }
 
 data "template_file" "ssh_config" {
-  count = var.data-node-count
   template = "${file("${path.module}/ssh.tpl")}"
   vars = {
-    host_ip  = "${element(aws_instance.re.*.public_ip, count.index)}"
     vpc_name = "${var.vpc-name}"
-    ncount   = "${count.index}"
   }
+  depends_on = ["aws_instance.re", "aws_eip_association.re-eip-assoc"]
 }
 
 ###############################################################################
@@ -47,9 +46,8 @@ resource "null_resource" "inventory-setup" {
 }
 
 resource "null_resource" "ssh-setup" {
-  count = var.data-node-count
   provisioner "local-exec" {
-    command = "echo \"${element(data.template_file.ssh_config.*.rendered, count.index)}\" > /tmp/${var.vpc-name}_node_${count.index}.cfg"
+    command = "echo \"${data.template_file.ssh_config.rendered}\" > /tmp/${var.vpc-name}_node.cfg"
   }
   depends_on = ["data.template_file.ssh_config"]
 }

+ 1 - 1
ssh.tpl

@@ -1,4 +1,4 @@
-Host ${host_ip}
+Host *
   User ubuntu
   IdentityFile ~/.ssh/${vpc_name}.pem
   ForwardAgent yes