No commit activity in last 3 years
No release in over 3 years
Expand hostlist expression like those defined in pdsh or Ansible inventory files. An expression like "host-[1-3].com" will expand into an array containing the elements host-1.com, host-2.com and host-3.com See https://github.com/udondan/hostlist_expression-ruby for documentation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

hostlist_expression

Gem Version Gem Version

Ruby gem for expanding hostlist expressions.

An expression like host-[1-3].com will expand into an array containing these elements:

host-1.com
host-2.com
host-3.com

This gem supports numeric and alphabetic ranges and sequences, and any combination.

By default both characters : (Ansible style) and - (pdsh style) are interpreted as range connectors.

Numeric ranges can have leading zeros [01-99].

With commata you can define sequences: [1,3,5].

A complex example with all variations:

Expression: host-[A-C]-[c,d,001-003].com

Result:

host-A-c.com
host-A-d.com
host-A-001.com
host-A-002.com
host-A-003.com
host-B-c.com
host-B-d.com
host-B-001.com
host-B-002.com
host-B-003.com
host-C-c.com
host-C-d.com
host-C-001.com
host-C-002.com
host-C-003.com

Please note, in an alphabetic range both items are required to be either lowercase or uppercase, you can't mix. A range like [A-c] will throw an exception.

Usage:

require "hostlist_expression"
hosts = hostlist_expression("host-[1-3].com")
print hosts

# => ["host-1.com", "host-2.com", "host-3.com"]

You may optionally pass custom characters for range definitions as 2nd parameter. (String or Array)

hosts = hostlist_expression("host-[1~3].com", "~")
hosts = hostlist_expression("host-[1~3,A-C,x/z].com", ["~", "-", "/"])

License

MIT