Loop over ansible_devices and select any physical disk that is not sda for inclusion into volume group

2k views Asked by At

I have a requirement to build two logical volumes. sda1 will always form /root and be partitioned up for logs and such, but /application may include anywhere from one to four additional disks. I know they will always begin with sdb and continue on to sde or sdf. I can think of a couple of different quick and dirty solutions like just running a bash command that builds a list to be registered as a variable, but what I would like to do instead is pull down from the ansible_devices part of Ansible setup facts and match a regex of sd[b-z]. I know it's unlikely I will ever have an sdz, but I want to keep this as flexible as possible. Does anyone have a good technique for this? Is a jinja2 filter the wrong approach?

1

There are 1 answers

0
Konstantin Suvorov On

You can use select filter with match test:

{{ ansible_devices.keys() | select('match','sd[b-c]') | list }}

Using map('‌​regex_replace','^','‌​/dev/') to prepend every string in a list is fine.