Pārlūkot izejas kodu

move configs for ansible to local

Chris Mague 4 gadi atpakaļ
vecāks
revīzija
98a3b80588
6 mainītis faili ar 51 papildinājumiem un 13 dzēšanām
  1. 1 3
      .gitignore
  2. 1 1
      .terraform-version
  3. 1 0
      inventories/README.md
  4. 6 0
      inventories/inventory.ctmpl
  5. 12 0
      inventories/ssh.ctmpl
  6. 30 9
      main.tf

+ 1 - 3
.gitignore

@@ -1,11 +1,9 @@
 cloud-tmux
 .terraform/
 terraform.tfstate*
-<<<<<<< HEAD
 cloud-tmux
-=======
 ansible/*.retry
 inventories/*.ini
+inventories/*.cfg
 ansible/raft_group_setup
 ansible/roles/*
->>>>>>> 650c625a384961385a2361e14ba70eeeceb21a30

+ 1 - 1
.terraform-version

@@ -1 +1 @@
-0.12.0-beta2
+0.12.26

+ 1 - 0
inventories/README.md

@@ -0,0 +1 @@
+# This is were we generate our files

+ 6 - 0
inventories/inventory.ctmpl

@@ -0,0 +1,6 @@
+[nodes]
+%{ for node in nodes ~}
+${node} ansible_ssh_common_args='-o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -F ${path}/inventories/ssh.cfg'
+%{ endfor ~}
+[tester]
+${tester} ansible_ssh_common_args='-o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -F  ${path}/inventories/ssh.cfg'

+ 12 - 0
inventories/ssh.ctmpl

@@ -0,0 +1,12 @@
+Host *
+  User ${ssh-user}
+  IdentityFile ~/.ssh/${ssh-key}
+  ForwardAgent yes
+  GSSAPIAuthentication no
+  VerifyHostKeyDNS no
+  HashKnownHosts no
+  TCPKeepAlive yes
+  ServerAliveInterval 300
+  StrictHostKeyChecking no
+  UserKnownHostsFile=/dev/null
+  IdentitiesOnly yes

+ 30 - 9
main.tf

@@ -53,8 +53,8 @@ module "tmux" {
 resource "aws_instance" "re" {
   ami                    = data.aws_ami.re-ami.id
   instance_type          = "m5a.xlarge"
-  availability_zone      = "${element(var.vpc-azs, 1)}"
-  subnet_id              = "${element(module.vpc.subnets-public, 1)}"
+  availability_zone      = element(var.vpc-azs, 1)
+  subnet_id              = element(module.vpc.subnets-public, 1)
   vpc_security_group_ids = [module.nodes.re-security-group]
   source_dest_check      = false
   key_name               = var.vpc-name
@@ -68,9 +68,9 @@ resource "aws_eip" "re-eip" {
 }
 
 resource "aws_eip_association" "re-eip-assoc" {
-  instance_id   = "${element(aws_instance.re.*.id, 1)}"
-  allocation_id = "${element(aws_eip.re-eip.*.id, 1)}"
-  depends_on    = ["aws_instance.re", "aws_eip.re-eip"]
+  instance_id   = element(aws_instance.re.*.id, 1)
+  allocation_id = element(aws_eip.re-eip.*.id, 1)
+  depends_on    = [aws_instance.re, aws_eip.re-eip]
 }
 
 
@@ -79,12 +79,12 @@ resource "null_resource" "remote-config" {
     connection {
       user        = "ubuntu"
       host        = aws_eip.re-eip.public_ip
-      private_key = "${file("~/.ssh/${var.vpc-name}.pem")}"
+      private_key = file("~/.ssh/${var.vpc-name}.pem")
       agent       = true
     }
     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"]
+  depends_on = [aws_instance.re, aws_eip_association.re-eip-assoc]
 }
 
 output "tmux" {
@@ -92,7 +92,7 @@ output "tmux" {
 }
 
 data "template_file" "raft_group_setup" {
-  template = "${file("${path.module}/raft_group_setup.tpl")}"
+  template = file("${path.module}/raft_group_setup.tpl")
   vars = {
     node1 = module.nodes.node-internal-ips[0]
     node2 = module.nodes.node-internal-ips[1]
@@ -104,8 +104,29 @@ resource "null_resource" "raft_group_setup" {
   provisioner "local-exec" {
     command = "echo \"${data.template_file.raft_group_setup.rendered}\" > ${path.module}/ansible/raft_group_setup"
   }
-  depends_on = ["data.template_file.raft_group_setup"]
+  depends_on = [data.template_file.raft_group_setup]
 }
 
+resource "local_file" "inventory" {
+  content = templatefile("${path.module}/inventories/inventory.ctmpl",
+              { 
+                nodes  = module.nodes.node-ips
+                tester = aws_eip.re-eip.public_ip
+                path   = abspath(path.module)
+              }
+          )
+  filename        = "${path.module}/inventories/inventory.ini"
+  file_permission = "0644"
+}
 
 
+resource "local_file" "ssh_config" {
+  content = templatefile("${path.module}/inventories/ssh.ctmpl",
+              { 
+                ssh-key  = "${var.vpc-name}.pem"
+                ssh-user = "ubuntu"
+              }
+          )
+  filename        = "${path.module}/inventories/ssh.cfg"
+  file_permission = "0644"
+}