From 9d9d4fdc70ec0ac276f3795f5ccea39d6b94b995 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 23 Apr 2020 04:59:13 +0200 Subject: further cleanup host bootstraping --- common/cloud-install.yml | 8 +++++++- common/utils.sh | 4 ++-- common/vm-install.yml | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/cloud-install.yml b/common/cloud-install.yml index 57ebc9e6..e21d4bf1 100644 --- a/common/cloud-install.yml +++ b/common/cloud-install.yml @@ -29,7 +29,13 @@ roles: - role: cloud/post-install -- import_playbook: "../{{ install_environment }}/{{ hostvars[install_hostname].install_playbook | default(install_hostname) }}.yml" +- name: run host playbook + vars: + params: + files: + - "../{{ install_environment }}/{{ install_hostname }}.yml" + - "../{{ install_environment }}/{{ install_playbook | default('common') }}.yml" + import_playbook: "{{ q('first_found', params) | first }}" - name: reboot and wait for machine come back hosts: "{{ install_hostname }}" diff --git a/common/utils.sh b/common/utils.sh index 262926c7..bb14381e 100644 --- a/common/utils.sh +++ b/common/utils.sh @@ -19,8 +19,8 @@ ansible_variable__get() { 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) + local _result=$(env ANSIBLE_STDOUT_CALLBACK="json" ansible "$_hosts" -m debug -a "msg={{ $_var_name }}" | \ + jq -r '.plays[].tasks[].hosts[] | select(.failed != true) | .msg' | sort | uniq) if [ $? -ne 0 ] || [ -z "$_result" ]; then print_error "failed to get value of variable '$_var_name' for host(s) '$_hosts'" return 1 diff --git a/common/vm-install.yml b/common/vm-install.yml index c3e7a25c..d449926e 100644 --- a/common/vm-install.yml +++ b/common/vm-install.yml @@ -58,7 +58,13 @@ - role: vm/guest when: install_distro in ['debian', 'ubuntu'] -- import_playbook: "../{{ install_environment }}/{{ hostvars[install_hostname].install_playbook | default(install_hostname) }}.yml" +- name: run host playbook + vars: + params: + files: + - "../{{ install_environment }}/{{ install_hostname }}.yml" + - "../{{ install_environment }}/{{ install_playbook | default('common') }}.yml" + import_playbook: "{{ q('first_found', params) | first }}" - name: reboot and wait for VM come back hosts: "{{ install_hostname }}" -- cgit v1.2.3