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?
Asked
Active
Viewed 1,897 times
0
-
This is what I've come up with so far while playing around: {{ ansible_devices.keys()|difference(['sr0','sda','fd0'])|map('regex_replace','^','/dev/')|join(',') }}. I think that's going to be the solution, but I'm open to other ideas. – eightbitdino Sep 04 '17 at 22:47
1 Answers
1
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.

Konstantin Suvorov
- 65,183
- 9
- 162
- 193