Update stor4nfv install scripts according to opensds aruba release
[stor4nfv.git] / ci / ansible / roles / osdsdock / scenarios / lvm.yml
1 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.\r
2 #\r
3 # Licensed under the Apache License, Version 2.0 (the "License");\r
4 # you may not use this file except in compliance with the License.\r
5 # You may obtain a copy of the License at\r
6 #\r
7 #     http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 # Unless required by applicable law or agreed to in writing, software\r
10 # distributed under the License is distributed on an "AS IS" BASIS,\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 # See the License for the specific language governing permissions and\r
13 # limitations under the License.\r
14 \r
15 ---\r
16 - name: install lvm2 ang tgt external package when lvm backend enabled\r
17   apt:\r
18     name: "{{ item }}"\r
19     state: present\r
20   with_items:\r
21     - lvm2\r
22     - tgt\r
23     - thin-provisioning-tools\r
24 \r
25 - name: configure lvm section in opensds global info if specify lvm backend\r
26   shell: |\r
27     cat >> opensds.conf <<OPENSDS_GLOABL_CONFIG_DOC\r
28 \r
29     [lvm]\r
30     name = {{ lvm_name }}\r
31     description = {{ lvm_description }}\r
32     driver_name = {{ lvm_driver_name }}\r
33     config_path = {{ lvm_config_path }}\r
34   args:\r
35     chdir: "{{ opensds_config_dir }}"\r
36   ignore_errors: yes\r
37 \r
38 - name: copy opensds lvm backend file to lvm config path if specify lvm backend\r
39   copy:\r
40     src: ../../../group_vars/lvm/lvm.yaml\r
41     dest: "{{ lvm_config_path }}"\r
42 \r
43 - name: create directory to volume group file\r
44   file:\r
45     path: "{{ opensds_work_dir }}/volumegroups"\r
46     state: directory\r
47     recurse: yes\r
48 \r
49 - name: create volume group in thin mode\r
50   shell:\r
51     _raw_params: |\r
52       function _create_lvm_volume_group {\r
53           local vg=$1\r
54           local size=$2\r
55 \r
56           local backing_file={{ opensds_work_dir }}/volumegroups/${vg}.img\r
57           if ! sudo vgs $vg; then\r
58               # Only create if the file doesn't already exists\r
59               [[ -f $backing_file ]] || truncate -s $size $backing_file\r
60               local vg_dev\r
61               vg_dev=`sudo losetup -f --show $backing_file`\r
62 \r
63               # Only create physical volume if it doesn't already exist\r
64               if ! sudo pvs $vg_dev; then\r
65                   sudo pvcreate $vg_dev\r
66               fi\r
67 \r
68               # Only create volume group if it doesn't already exist\r
69               if ! sudo vgs $vg; then\r
70                   sudo vgcreate $vg $vg_dev\r
71               fi\r
72           fi\r
73       }\r
74       modprobe dm_thin_pool\r
75       _create_lvm_volume_group {{ opensds_volume_group }} 10G\r
76   args:\r
77     executable: /bin/bash\r
78   become: true\r