|
10 | 10 | # are not fixed and cannot be depended upon to locate specific |
11 | 11 | # devices or their content. |
12 | 12 | # |
13 | | -# The block device name attached to each volume is fixed by |
14 | | -# terraform but not exposed to Ansible or the guest. It has to be |
15 | | -# extracted from terraform state and matched to a volume ID, which |
16 | | -# appears as the device serial number. |
| 13 | +# Instead, rely on a directory created by a udev rule to find the |
| 14 | +# EBS block devices attached on behalf of kdevops. The rule |
| 15 | +# guarantees the symlinks names always point to the same block |
| 16 | +# device. |
17 | 17 | # |
18 | | -# The root EBS device is not included in terraform's block device |
19 | | -# map, so is easily avoided. |
20 | | -# |
21 | | - |
22 | | -- name: Retrieve the block_device_map from terraform |
23 | | - delegate_to: localhost |
24 | | - run_once: true |
25 | | - ansible.builtin.command: |
26 | | - chdir: "{{ topdir_path }}/terraform/aws/" |
27 | | - cmd: "terraform output -json block_device_map" |
28 | | - register: terraform_output |
29 | | - changed_when: false |
30 | 18 |
|
31 | | -- name: Exclude the device that will house the /data file system |
32 | | - vars: |
33 | | - block_device_dict: "{{ terraform_output.stdout | from_json }}" |
34 | | - local_map: "{{ block_device_dict[inventory_hostname] }}" |
35 | | - ansible.builtin.set_fact: |
36 | | - ebs_volume_ids: "{{ ebs_volume_ids + ['nvme-Amazon_Elastic_Block_Store_' + item.value | regex_replace('-', '')] }}" |
37 | | - when: |
38 | | - item.key != data_device |
39 | | - with_dict: "{{ local_map }}" |
| 19 | +- name: Retrieve list of symlinks residing under /dev/disk/kdevops |
| 20 | + ansible.builtin.find: |
| 21 | + file_type: link |
| 22 | + paths: "/dev/disk/kdevops" |
| 23 | + excludes: "{{ data_device | basename }}" |
| 24 | + register: find_output |
40 | 25 |
|
41 | | -- name: Add unused EBS volumes to the volume list |
| 26 | +- name: Extract device paths from find output |
42 | 27 | ansible.builtin.set_fact: |
43 | | - physical_volumes: "{{ physical_volumes + ['/dev/' + item.key] }}" |
44 | | - when: |
45 | | - - item.value.links.ids | intersect(ebs_volume_ids) | list | count > 0 |
46 | | - loop_control: |
47 | | - label: "Adding block device: /dev/{{ item.key }}" |
48 | | - with_dict: "{{ ansible_devices }}" |
| 28 | + physical_volumes: "{{ find_output.files | map(attribute='path') | list }}" |
0 commit comments