Skip to content

Commit 7b07c9f

Browse files
authored
Merge pull request #41 from t2d/master
Run virt_volume.sh also in check mode
2 parents b1301ca + 2679efb commit 7b07c9f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

files/virt_volume.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
# Parse options
2121
OPTIND=1
2222

23-
while getopts ":n:p:c:f:i:b:" opt; do
23+
while getopts ":n:p:c:f:i:b:a:" opt; do
2424
case ${opt} in
2525
n) NAME=$OPTARG;;
2626
p) POOL=$OPTARG;;
2727
c) CAPACITY=$OPTARG;;
2828
f) FORMAT=$OPTARG;;
2929
i) IMAGE=$OPTARG;;
3030
b) BACKING_IMAGE=$OPTARG;;
31+
a) CHECK=$OPTARG;;
3132
\?)
3233
echo "Invalid option: -$OPTARG" >&2
3334
exit 1
@@ -66,6 +67,12 @@ elif ! echo "$output" | grep 'Storage volume not found' >/dev/null 2>&1; then
6667
exit $result
6768
fi
6869

70+
# Stop here in check mode, there will be a change
71+
if [[ $CHECK = "True" ]]; then
72+
echo '{"changed": true}'
73+
exit 0
74+
fi
75+
6976
# Create the volume.
7077
if [[ -n $BACKING_IMAGE ]]; then
7178
if [[ "$FORMAT" != 'qcow2' ]]; then

tasks/volumes.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
{% elif item.backing_image is defined %}
2626
-b {{ item.backing_image }}
2727
{% endif %}
28+
-a {{ ansible_check_mode }}
2829
with_items: "{{ volumes }}"
2930
when: item.device | default(libvirt_volume_default_device) == 'disk'
3031
environment: "{{ libvirt_vm_script_env }}"
3132
register: volume_result
3233
changed_when:
3334
- volume_result is success
3435
- (volume_result.stdout | from_json).changed | default(True)
36+
check_mode: False
3537
become: true

0 commit comments

Comments
 (0)