From 14b92f0ae1bf2df8c7632dc61884bd5e351679d1 Mon Sep 17 00:00:00 2001 From: John Trowbridge Date: Wed, 1 Mar 2017 15:34:56 -0500 Subject: [PATCH] Reset virt-customize args at the beginning of the role Without doing this, if a play includes multiple runs of the modify-image role, the virt-customize args keep growing. This can lead to unintentionally re-running scripts or re-uploading files. Since we now ignore user input for vc_args key it is renamed _vc_args, and the defaults are updated to reflect the variable being "private". Change-Id: I17cb09a084136cdaabf4d25dd684f594f1f546eb --- roles/modify-image/defaults/main.yml | 7 ------- roles/modify-image/tasks/main.yml | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/roles/modify-image/defaults/main.yml b/roles/modify-image/defaults/main.yml index be1b6bd65..0ed7c385a 100644 --- a/roles/modify-image/defaults/main.yml +++ b/roles/modify-image/defaults/main.yml @@ -18,13 +18,6 @@ modify_image_install_packages: [] # By default we use the global working directory for modifying images modify_image_working_dir: "{{ working_dir }}" -# virt-customize defaults -# vc_args can be used to pass any arbitrary arguments to virt-customize -vc_args: "" - -# the other "vc" vars below are converted to the correct virt-customize args, -# and are provided for convenience. - # ram and cpu are not set by default to take libguestfs defaults by default # modify_image_vc_ram: # modify_image_vc_cpu: diff --git a/roles/modify-image/tasks/main.yml b/roles/modify-image/tasks/main.yml index 98a4a6ca0..3da3c2e1a 100644 --- a/roles/modify-image/tasks/main.yml +++ b/roles/modify-image/tasks/main.yml @@ -11,37 +11,40 @@ yum: name=libguestfs-tools-c state=latest become: true +- name: virt-customize args --> reset private var + set_fact: _vc_args="" + - name: virt-customize args --> memory - set_fact: vc_args="{{ vc_args }} -m {{ modify_image_vc_ram }}" + set_fact: _vc_args="{{ _vc_args }} -m {{ modify_image_vc_ram }}" when: modify_image_vc_ram is defined - name: virt-customize args --> cpu - set_fact: vc_args="{{ vc_args }} --smp {{ modify_image_vc_cpu }}" + set_fact: _vc_args="{{ _vc_args }} --smp {{ modify_image_vc_cpu }}" when: modify_image_vc_cpu is defined - name: virt-customize args --> verbose output - set_fact: vc_args="{{ vc_args }} -v" + set_fact: _vc_args="{{ _vc_args }} -v" when: modify_image_vc_verbose|bool - name: virt-customize args --> trace/debug output - set_fact: vc_args="{{ vc_args }} -x" + set_fact: _vc_args="{{ _vc_args }} -x" when: modify_image_vc_trace|bool - name: virt-customize args --> upload files - set_fact: vc_args="{{ vc_args }} --upload {{ item.src }}:{{ item.dest }}" + set_fact: _vc_args="{{ _vc_args }} --upload {{ item.src }}:{{ item.dest }}" with_items: "{{ modify_image_upload_files }}" - name: virt-customize args --> install packages - set_fact: vc_args="{{ vc_args }} --install {{ modify_image_install_packages|join(",") }}" + set_fact: _vc_args="{{ _vc_args }} --install {{ modify_image_install_packages|join(",") }}" when: modify_image_install_packages - name: virt-customize args --> modify script - set_fact: vc_args="{{ vc_args }} --run {{ modify_script }}" + set_fact: _vc_args="{{ _vc_args }} --run {{ modify_script }}" when: modify_script is defined - name: Run virt-customize on the provided image shell: > - virt-customize {{ vc_args }} + virt-customize {{ _vc_args }} -a {{ image_to_modify }} > {{ modify_script|default('modify_image') }}.log 2>&1 environment: