How to get a hostname that contains a specific string from a group in Ansible

I am using Ansible and need to find my database server for use in the configuration file.

I have a group of all database servers:, groups.rdsand I know that the server I'm looking for contains a specific string, for example. "Development".

What is the cleanest way to find this hostname?

I am looking for something like this: groups.rds.contains("development").first()

+4
source share
1 answer

You can do this with selectfilter in combination with match.

groups.rds | select("match", ".*production.*") | first

. , , () . , ?

- :

[non_rds]
some.unrelated.development.host

[rds]
some.production.host
some.staging.host
some.development.host

[production]
some.production.host

[staging]
some.staging.host

[development]
some.development.host
some.unrelated.development.host

:

groups.rds | intersect(groups.development) | first

, rds development, some.development.host.

+2

Source: https://habr.com/ru/post/1628435/


All Articles