|
44 | 44 | path={{ artefact_dir }}/{{ output_box }} |
45 | 45 | register: box_status |
46 | 46 |
|
47 | | -- name: Create box file using vagrant, and include a specific Vagrant file. |
48 | | - command: vagrant package --output {{ artefact_dir }}/{{ output_box }} --vagrantfile ../../guest_resources/vagrantfiles/Vagrantfile_{{ vm_name }}_builtin |
| 47 | +# Determine whether or not an inbuilt Vagrantfile is supplied. If it is, we |
| 48 | +# package the box with it. Otherwise, we package the box without an in-built |
| 49 | +# Vagrantfile. |
| 50 | +# |
| 51 | +# By the way, "isreg" means "is a regular file?". |
| 52 | + |
| 53 | +- name: Define the path for in-built Vagrantfiles. |
| 54 | + set_fact: |
| 55 | + inbuilt_vagrantfile_path: "{{ vm_dir }}/../../guest_resources/vagrantfiles" |
| 56 | + |
| 57 | +- name: Determine whether or not a builtin Vagrantfile exists for this target. |
| 58 | + stat: |
| 59 | + path: "{{ inbuilt_vagrantfile_path }}/Vagrantfile_{{ vm_name }}_builtin" |
| 60 | + register: vagrantfile |
| 61 | + |
| 62 | +- name: Create box file using vagrant, and include a built-in Vagrant file if it exists. |
| 63 | + command: vagrant package --output {{ artefact_dir }}/{{ output_box }} --vagrantfile {{ inbuilt_vagrantfile_path }}/Vagrantfile_{{ vm_name }}_builtin |
| 64 | + chdir={{ vm_dir }} |
| 65 | + creates={{ artefact_dir }}/{{ output_box }} |
| 66 | + when: vagrantfile.stat.exists and (not box_status.stat.exists or (box_status.stat.isreg and clobber_output)) |
| 67 | + |
| 68 | +- name: Create box file using vagrant without a built-in Vagrant file if it is absent. |
| 69 | + command: vagrant package --output {{ artefact_dir }}/{{ output_box }} |
49 | 70 | chdir={{ vm_dir }} |
50 | 71 | creates={{ artefact_dir }}/{{ output_box }} |
51 | | - when: not box_status.stat.exists or (box_status.stat.isreg and clobber_output) |
| 72 | + when: (not vagrantfile.stat.exists) and (not box_status.stat.exists or (box_status.stat.isreg and clobber_output)) |
52 | 73 |
|
53 | 74 | - name: Extract the virtual machine disk (VMDK) file from the box. |
54 | 75 | command: tar -xvf {{ output_box }} -C {{ artefact_dir }} ./box-disk1.vmdk |
|
0 commit comments