Initial commit
[ta/infra-ansible.git] / playbooks / create_osd_disk_configuration.yml
1 ---
2
3 # Copyright 2019 Nokia
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 - name: create osd disk configuration
18   hosts: osds
19   become: yes
20   become_method: sudo
21   become_user: root
22   gather_facts: no
23   tasks:
24
25   - name: get the ceph osd ids
26     shell: lsblk -r | grep ceph- | cut -d '-' -f2
27     register: ceph_osd_ids
28
29   - name: get the devices
30     shell: for part in $(lsblk -r | grep  ceph- | awk -F[^A-Za-z][0-9*] '{print $1}');do find -L /sys/block -maxdepth 2 -name $part|cut -d'/' -f4;done
31     register: osd_devices
32
33   - name: get the by-path disks
34     shell: file /dev/disk/by-path/* | grep -w {{ item }} | head -n 1 | awk '{print $1}' | sed 's/.$//'
35     with_items: "{{ osd_devices.stdout_lines }}"
36     register: by_path_tmp
37
38   - name: get the disk size
39     shell: lsblk -r | grep -w {{ item }} | awk '{print $4}'
40     with_items: "{{ osd_devices.stdout_lines }}"
41     register: disk_size_tmp
42
43   - name: initialize list variables
44     set_fact:
45       by_path: []
46       disk_size: []
47       disk_config: []
48       disk_config1: {}
49
50   - name: set by_path variable
51     set_fact:
52       by_path: "{{ by_path }} + {{ item.stdout_lines }} "
53     with_items: "{{ by_path_tmp.results }}"
54
55   - name: set disk_size variable
56     set_fact:
57       disk_size: "{{ disk_size }} + {{ item.stdout_lines }} "
58     with_items: "{{ disk_size_tmp.results }}"
59
60   - name: populate disk_config
61     set_fact:
62       disk_config: "{{ disk_config +  [ {'osd_id': item.0, 'device': item.1, 'by-path': item.2,  'size': item.3, 'service_name': 'ceph-osd-disk-' + item.4 | string, 'systemd': 'ceph-osd@' + item.0 | string + '.service'} ] }}"
63     with_together:
64       - "{{ ceph_osd_ids.stdout_lines }}"
65       - "{{ osd_devices.stdout_lines }}"
66       - "{{ by_path }}"
67       - "{{ disk_size }}"
68       - "{{ by_path_disks['osd_disks_ids'] }}"
69
70   - name: dump disk_config variable
71     action: template src=osd_disk_configuration.j2 dest=/tmp/{{ hostname }}-disks.json  mode=644