I am trying to create an ansible role that depends on other roles only if the hostname of the machine it's being run on contains a certain string. For example:
dependencies:
- { role: example-role, when: "'hostname' in ansible_hostname" }
As it is, the role will run when the hostname of the machine contains the phrase "hostname". However, many of the machines in our building have hostnames that are upper case, for example, it may contain "HOSTNAME". In this case, the above statement will not work. How can I make this work (aside from duplicating the line and putting "hostname" in all caps) to ignore letter cases?
Convert the string to lowercase and only check that. Like this:
dependencies:
- { role: example-role, when: "'hostname' in ansible_hostname|lower" }