From 58e9c8db6e35eef1c24ec8ac6016651d6d110338 Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Fri, 26 Aug 2016 11:17:37 -0700 Subject: [PATCH] Fix deprecation warning for undefined variables Provide a default empty variable for 'bootstrap_host_data_disk_device'. Tasks which make use of this variable within with_items lists have been updated to evaluate that it has been set before executing. 'with_' clauses are evaluated before 'when' clauses. In Ansible 1.9 tasks are silently skipped when a variable within a 'with_' clause is undefined, Ansible 2 provides a deprecation warning. Change-Id: I66d7c15a43a70237b35d8ba7325d24e3b7206208 --- tests/roles/bootstrap-host/defaults/main.yml | 2 +- .../bootstrap-host/tasks/check-requirements.yml | 16 ++++++---------- tests/roles/bootstrap-host/tasks/main.yml | 3 +-- .../bootstrap-host/tasks/prepare_data_disk.yml | 8 ++++---- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/roles/bootstrap-host/defaults/main.yml b/tests/roles/bootstrap-host/defaults/main.yml index 82a37ec896..a5f573e42c 100644 --- a/tests/roles/bootstrap-host/defaults/main.yml +++ b/tests/roles/bootstrap-host/defaults/main.yml @@ -70,7 +70,7 @@ bootstrap_host_bridge_storage_ports: none # be destroyed and repartitioned. # # Specify the secondary disk device to use. -#bootstrap_host_data_disk_device: vdb +bootstrap_host_data_disk_device: null # # Boolean value to force the repartitioning of the secondary device. bootstrap_host_data_disk_device_force: no diff --git a/tests/roles/bootstrap-host/tasks/check-requirements.yml b/tests/roles/bootstrap-host/tasks/check-requirements.yml index 14faa74d12..e6279e9982 100644 --- a/tests/roles/bootstrap-host/tasks/check-requirements.yml +++ b/tests/roles/bootstrap-host/tasks/check-requirements.yml @@ -22,8 +22,7 @@ - name: Identify the space available in / shell: | df -BK / | awk '/^[^Filesystem]/ {print $4}' | sed 's/K//' - when: - - bootstrap_host_data_disk_device is not defined + when: bootstrap_host_data_disk_device == None changed_when: false register: root_space_available tags: @@ -34,7 +33,7 @@ set_fact: host_root_space_available_bytes: "{{ ( root_space_available.stdout | int) * 1024 | int }}" when: - - bootstrap_host_data_disk_device is not defined + - bootstrap_host_data_disk_device == None tags: - check-disk-size @@ -43,7 +42,7 @@ host_data_disk_sectors: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectors'] | int) }}" host_data_disk_sectorsize: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectorsize'] | int) }}" when: - - bootstrap_host_data_disk_device is defined + - bootstrap_host_data_disk_device != None tags: - check-disk-size @@ -51,8 +50,7 @@ - name: Calculate data disk size set_fact: host_data_disk_size_bytes: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}" - when: - - bootstrap_host_data_disk_device is defined + when: bootstrap_host_data_disk_device != None tags: - check-disk-size @@ -67,8 +65,7 @@ assert: that: | (host_root_space_available_bytes | int) >= (host_data_disk_min_size_bytes | int) - when: - - bootstrap_host_data_disk_device is not defined + when: bootstrap_host_data_disk_device == None tags: - check-disk-size @@ -76,8 +73,7 @@ assert: that: | (host_data_disk_size_bytes | int) >= (host_data_disk_min_size_bytes | int) - when: - - bootstrap_host_data_disk_device is defined + when: bootstrap_host_data_disk_device != None tags: - check-disk-size diff --git a/tests/roles/bootstrap-host/tasks/main.yml b/tests/roles/bootstrap-host/tasks/main.yml index f37d6e510a..fa74d169df 100644 --- a/tests/roles/bootstrap-host/tasks/main.yml +++ b/tests/roles/bootstrap-host/tasks/main.yml @@ -49,8 +49,7 @@ # Prepare the data disk, if one is provided - include: prepare_data_disk.yml - when: - - bootstrap_host_data_disk_device is defined + when: bootstrap_host_data_disk_device != None tags: - prepare-data-disk diff --git a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml index 81b00c4de1..e29d669817 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_data_disk.yml @@ -55,8 +55,8 @@ dev: "{{ item }}" when: data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool with_items: - - "/dev/{{ bootstrap_host_data_disk_device }}1" - - "/dev/{{ bootstrap_host_data_disk_device }}2" + - "/dev/{{ bootstrap_host_data_disk_device }}1" + - "/dev/{{ bootstrap_host_data_disk_device }}2" tags: - format-data-partitions @@ -67,7 +67,7 @@ fstype: ext4 state: mounted with_items: - - { mount_point: /openstack, device: "/dev/{{ bootstrap_host_data_disk_device }}1"} - - { mount_point: /var/lib/lxc, device: "/dev/{{ bootstrap_host_data_disk_device }}2"} + - { mount_point: /openstack, device: "/dev/{{ bootstrap_host_data_disk_device }}1"} + - { mount_point: /var/lib/lxc, device: "/dev/{{ bootstrap_host_data_disk_device }}2"} tags: - mount-data-partitions