Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update logic for cloud-init and variable names for resolving ambiguity #1636

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions linchpin/provision/roles/libvirt/tasks/provision_libvirt_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
- name: set cloud config default
set_fact:
cloud_config: "{{ res_def['cloud_config'] }}"
cloud_config_used: true
cloud_init_used: true

- name: "check cloud_config is used or not"
set_fact:
cloud_config_used: "{{ true if (cloud_config['users'] == [] and cloud_config['run_commands'] == []) else false }}"
cloud_init_used: "{{ true if (cloud_config['users'] != [] and cloud_config['run_commands'] is not defined ) else false }}"

- name: "set empty local_image_path"
set_fact:
Expand Down Expand Up @@ -166,7 +166,7 @@
loop_var: definition
remote_user: "{{ res_def['remote_user'] }}"
delegate_to: "{{ uri_hostname }}"
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "Create directories"
file:
Expand All @@ -178,7 +178,7 @@
- ["{{ res_def['name_separator'] }}"]
loop_control:
loop_var: definition
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "Prepare cloud-config/user-data-local"
template:
Expand All @@ -192,7 +192,7 @@
loop_var: definition
vars:
cloudconfig_users: "{{ cloud_config['users'] | default([]) }}"
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "Prepare cloud-config/user-data-remote"
template:
Expand All @@ -206,7 +206,7 @@
loop_var: definition
remote_user: "{{ res_def['remote_user'] }}"
delegate_to: "{{ uri_hostname }}"
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "Prepare cloud-config/meta-data"
template:
Expand All @@ -219,7 +219,7 @@
- ["{{ res_def['domain'] }}"]
loop_control:
loop_var: definition
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "Prepare cloud-config/meta-data remote"
template:
Expand All @@ -234,7 +234,7 @@
loop_var: definition
remote_user: "{{ res_def['remote_user'] }}"
delegate_to: "{{ uri_hostname }}"
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "localhost: Generate ci data cd image for cloud-init when cloud config is defined"
command: mkisofs -file-mode 0666 -o /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}.iso -V cidata -r -J --quiet /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}/user-data /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}/meta-data
Expand All @@ -244,7 +244,7 @@
- ["{{ res_def['name_separator'] }}"]
loop_control:
loop_var: definition
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname == 'localhost' and virt_type == "cloud-init" and cloud_init_used

- name: "remote_host: Generate ci data cd image for cloud-init when cloud config is defined"
command: mkisofs -file-mode 0666 -o /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}.iso -V cidata -r -J --quiet /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}/user-data /tmp/vm-{{ definition[0] }}{{ definition[2] }}{{ definition[1] }}/meta-data
Expand All @@ -256,7 +256,7 @@
loop_var: definition
remote_user: "{{ res_def['remote_user'] }}"
delegate_to: "{{ uri_hostname }}"
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and uri_hostname != 'localhost' and virt_type == "cloud-init" and cloud_init_used

- set_fact:
vm_xml: "{% if res_def.xml is defined %}{{workspace}}/{{res_def.xml}}{% else %}libvirt_node.xml.j2{%endif%}"
Expand Down Expand Up @@ -334,7 +334,7 @@
- ["{{ res_def['name_separator'] }}"]
loop_control:
loop_var: definition
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_init_used

- name: "Remove cdrom (cloud-init)"
command: virsh -c {{ definition[1] }} change-media {{ definition[0] }}{{ definition[3] }}{{ definition[2] }} hda --eject --config
Expand All @@ -346,7 +346,7 @@
loop_control:
loop_var: definition
ignore_errors: yes
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_init_used


- name: sync memory data to disk
Expand All @@ -366,7 +366,7 @@
loop_control:
loop_var: definition
ignore_errors: no
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_config_used
when: node_exists['failed'] is defined and virt_type == "cloud-init" and cloud_init_used

- name: "dump node data"
virt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<emulator>{{ qemu_path }}qemu-kvm</emulator>
{% endif %}

{% if virt_type == 'cloud-init' and cloud_config_used %}
{% if virt_type == 'cloud-init' and cloud_init_used %}
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/tmp/vm-{{ libvirt_resource_name }}{{ definition[4] }}{{ definition[1] }}.iso'/>
Expand Down