Added seed code for caas-lcm.
[ta/caas-lcm.git] / deploy / roles / bm_onboard / tasks / main.yml
1 ---
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - name: set cloudadmin home
17   set_fact:
18     home: "/home/{{ users.admin_user_name }}/"
19
20 - name: find app images
21   find:
22     paths: "{{ home }}"
23     patterns: '{{app_image_name}}*'
24   register: app_image_properties
25
26 - fail:
27     msg: "There is no app image in {{ home }} folder"
28   when: app_image_properties.files == []
29
30 - name: get app image extension
31   shell: "qemu-img info {{ app_image_properties.files[0].path }} | grep \"file format:\" | cut -d\" \" -f3"
32   register: app_image_format
33
34 - name: convert image if needed
35   shell: "qemu-img convert -f {{ app_image_format.stdout }} -O raw {{ app_image_properties.files[0].path }} {{ app_image_properties.files[0].path }}.raw"
36   when: app_image_format.stdout != "raw"
37
38 - name: Run existing SU ansible to onboard Swift image content to deployed Swift workspace
39   shell: '/usr/bin/ansible-playbook -i {{ lcm_path }}/deploy/inventory {{ lcm_path }}/su/su_prepare_playbook.yml -e "swift_image_path={{ app_image_properties.files[0].path }}.raw"'
40
41 - name: find app images
42   find:
43     paths: "{{ home }}"
44     patterns: "{{ app_image_properties.files[0].path | basename }}*"
45   register: files_to_delete
46
47 - name: delete app images
48   file:
49     path: "{{ item.path }}"
50     state: absent
51   with_items: "{{ files_to_delete.files }}"
52