Explorar el Código

ensure that we don't try to attach volumes in ansible if they are disabled

Chris Mague hace 4 años
padre
commit
a04ccd3a7a
Se han modificado 4 ficheros con 15 adiciones y 4 borrados
  1. 1 0
      .gitignore
  2. 2 0
      ansible/default.yaml
  3. 11 3
      ansible/playbook.yml
  4. 1 1
      provisioning.tf

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 .terraform/*
 test/.terraform/*
+test/terraform.tfstat*
 Gemfile.lock
 ansible/*.retry
 ansible/roles/*

+ 2 - 0
ansible/default.yaml

@@ -0,0 +1,2 @@
+---
+enable_volumes: "{{ ENABLE_VOLUMES|default(true) }}"

+ 11 - 3
ansible/playbook.yml

@@ -6,7 +6,14 @@
   become_method: sudo
   gather_facts: yes
 
+
   pre_tasks:
+    - name: Load vars
+      include_vars: "{{ item }}"
+      with_first_found:
+        - "{{ ansible_hostname }}.yaml"
+        - "default.yaml"
+
     - name: Update Apt Cache
       apt: update_cache=yes cache_valid_time=86400
       when: ansible_os_family == "Debian"
@@ -46,25 +53,26 @@
         fstype: ext4
         #dev: "/dev/xvdh"
         dev: "/dev/nvme1n1"
+      when: enable_volumes
     - name: mount ephemeral dir filesystem
       mount:
         name: /redis/ephemeral
-        #src: /dev/xvdh
         src: /dev/nvme1n1
         fstype: ext4
         state: mounted
+      when: enable_volumes
     - name: create persistant filesystem
       filesystem:
         fstype: ext4
-        #dev: "/dev/xvdj"
         dev: "/dev/nvme2n1"
+      when: enable_volumes
     - name: mount persistant dir filesystem
       mount:
         name: /redis/persistant
-        #src: /dev/xvdj
         src: /dev/nvme2n1
         fstype: ext4
         state: mounted
+      when: enable_volumes
 
   tasks:
     - name: create download directory

+ 1 - 1
provisioning.tf

@@ -57,7 +57,7 @@ resource "null_resource" "ssh-setup" {
 resource "null_resource" "ansible-run" {
   count = var.data-node-count
   provisioner "local-exec" {
-    command = "ansible-playbook ${path.module}/ansible/playbook.yml --private-key ${local.ssh_key_path} -i /tmp/${var.vpc-name}_node_${count.index}.ini --become -e 'MYENV=1'"
+    command = "ansible-playbook ${path.module}/ansible/playbook.yml --private-key ${local.ssh_key_path} -i /tmp/${var.vpc-name}_node_${count.index}.ini --become -e 'ENABLE_VOLUMES=${var.enable-volumes}'"
   }
   depends_on = ["null_resource.remote-config"]
 }