summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2018-12-08 16:53:43 +0100
committerChristian Pointner <equinox@spreadspace.org>2018-12-08 16:53:43 +0100
commitee42cc8340f26be2316120a1434c5289d5927da2 (patch)
tree638ec7b167869c730fd7398a35118c330644276e /common
parentstrip old and not yet used hosts (diff)
improve handling of environment groups
Diffstat (limited to 'common')
-rw-r--r--common/utils.sh21
-rw-r--r--common/vm-install.yml47
2 files changed, 68 insertions, 0 deletions
diff --git a/common/utils.sh b/common/utils.sh
new file mode 100644
index 00000000..2749eda6
--- /dev/null
+++ b/common/utils.sh
@@ -0,0 +1,21 @@
+## this contains several helper functions
+
+get_ansible_variable() {
+ local _var_name="$1"
+ local _hosts="$2"
+
+ local _result=$(env ANSIBLE_STDOUT_CALLBACK="json" ansible "$_hosts" -m debug -a "var=$_var_name" | \
+ jq -r ".plays[].tasks[].hosts[].$_var_name" | sort | uniq)
+ if [ $? -ne 0 ] || [ -z "$_result" ]; then
+ return 1
+ fi
+
+ local _num_results=$(echo "$_result" | wc -l)
+ if [ $_num_results -ne 1 ]; then
+ echo "ERROR: hosts may only belong to one environment group but got: $(echo $_result | xargs | sed 's/ /, /g')"
+ return 1
+ fi
+
+ eval "$_var_name"='$(echo "$_result")'
+ return 0
+}
diff --git a/common/vm-install.yml b/common/vm-install.yml
new file mode 100644
index 00000000..a6faf827
--- /dev/null
+++ b/common/vm-install.yml
@@ -0,0 +1,47 @@
+---
+- name: preperations and sanity checks
+ hosts: "{{ vmname }}"
+ gather_facts: no
+ tasks:
+ - name: setup variables
+ set_fact:
+ vm_network_cooked: "{{ vm_network }}"
+ vm_install_cooked: "{{ vm_install }}"
+ - name: create temporary host group for vm host
+ add_host:
+ name: "{{ vm_install.host }}"
+ inventory_dir: "{{inventory_dir}}"
+ group: _vmhost_
+ # TODO: add some sanity checks
+
+- name: basic installation
+ hosts: _vmhost_
+ roles:
+ - role: vm/install
+
+- name: wait for new vm to start up
+ hosts: "{{ vmname }}"
+ gather_facts: no
+ tasks:
+ ## TODO: find a better way to fetch host key of new VMs
+ - name: disable ssh StrictHostKeyChecking for the next step
+ set_fact:
+ ansible_ssh_extra_args: -o StrictHostKeyChecking=no
+ - name: wait for vm to start up
+ wait_for_connection:
+ delay: 5
+ timeout: 120
+ - name: reenable StrictHostKeyChecking
+ set_fact:
+ ansible_ssh_extra_args: ""
+
+### TODO: fix path to host_playbook
+##- import_playbook: "host_playbooks/{{ vmname }}.yml"
+
+- name: reboot and wait for VM come back
+ hosts: "{{ vmname }}"
+ gather_facts: no
+ roles:
+ - role: reboot-and-wait
+ reboot_delay: 10
+ reboot_timeout: 120