disk wipeoff: Fix shell syntax for missing disk 18/2118/7
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Wed, 11 Dec 2019 17:06:34 +0000 (18:06 +0100)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Fri, 13 Dec 2019 15:13:40 +0000 (16:13 +0100)
When one of the disks defined in the vendors/product configuration
files is not present on the system, the wipeoff commands fail due to
likely broken shell syntax and duplicate commands.

Signed-off-by: Alexandru Antone <Alexandru.Antone@enea.com>
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Change-Id: I667d85bb0b3e47ae5297d8eb3b16df84bdc7317a

infra-ansible.spec
playbooks/destroy_data_and_partitions.yml
roles/cleanup_disks/tasks/destroy_data_and_partitions.yml

index 218c941..26a0402 100644 (file)
@@ -15,7 +15,7 @@
 
 Name:           infra-ansible
 Version:        %{_version}
-Release:        4%{?dist}
+Release:        5%{?dist}
 Summary:        Contains ansible playbook and roles for Akraino rec blueprint
 License:        %{_platform_licence}
 Source0:        %{name}-%{version}.tar.gz
index 89c5f26..ba187cd 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+- name: check whether disks exist and are block devices
+  stat: path={{ item }}
+  with_items: "{{ disks }}"
+  register: disks_stat
+
 - name: wipe off filesystems from disks
-  shell: "[ -b {{ item }} ] | /usr/sbin/wipefs --all --force {{ item }} || /usr/sbin/wipefs --all --force {{ item }}"
+  command: "/usr/sbin/wipefs --all --force {{ item.item }}"
   args:
     creates: /etc/storage/osd_disk_metadata.json
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk
 
 - name: destroy data from disks
-  shell: "[ -b {{ item }} ] | dd if=/dev/zero of={{ item }} count=200 bs=1M"
+  command: "dd if=/dev/zero of={{ item.item }} count=200 bs=1M"
   args:
     creates: /etc/storage/osd_disk_metadata.json
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk
 
 - name: destroy partitions from disks
-  shell: "[ -b {{ item }} ] | /usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item }} || /usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item }}"
+  command: "/usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item.item }}"
   args:
     creates: /etc/storage/osd_disk_metadata.json
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk
index 48aeff5..7e85904 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+- name: check whether disks exist and are block devices
+  stat: path={{ item }}
+  with_items: "{{ disks }}"
+  register: disks_stat
+
 - name: wipe off filesystems from disks
-  shell: "[ -b {{ item }} ] | /usr/sbin/wipefs --all --force {{ item }} || /usr/sbin/wipefs --all --force {{ item }}"
+  command: "/usr/sbin/wipefs --all --force {{ item.item }}"
   args:
     creates: "{{ creates_file }}"
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk
 
 - name: destroy data from disks
-  shell: "[ -b {{ item }} ] | dd if=/dev/zero of={{ item }} count=200 bs=1M"
+  command: "dd if=/dev/zero of={{ item.item }} count=200 bs=1M"
   args:
     creates: "{{ creates_file }}"
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk
 
 - name: destroy partitions from disks
-  shell: "[ -b {{ item }} ] | /usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item }} || /usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item }}"
+  command: "/usr/sbin/sgdisk --zap-all --clear --mbrtogpt -- {{ item.item }}"
   args:
     creates: "{{ creates_file }}"
-  with_items: "{{ disks }}"
+  with_items: "{{ disks_stat.results }}"
+  when: item.stat.exists and item.stat.isblk