filter_hosts
The filter_hosts
function takes two arguments:
hosts
: a table that contains the hosts to filter.pattern
: a string that contains the name or tag to filter the hosts. It can be a regular expression by adding~
at the beginning of the pattern.
The function returns a table that contains the filtered hosts.
Usage Example
local hosts = {
{
name = "server1",
address = "10.20.30.41",
tags = { "webserver", "database" },
},
{
name = "server2",
address = "10.20.30.42",
tags = { "webserver" },
},
{
name = "server3",
address = "10.20.30.43",
tags = { "database" },
},
}
local filtered_hosts = komandan.filter_hosts(hosts, "webserver")
This will return the table filtered_hosts
that contains only the hosts that have the name or tag webserver
.