Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore case sensitivity in Ansible when condition?

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?

like image 885
Michael Avatar asked Jul 15 '16 14:07

Michael


1 Answers

Convert the string to lowercase and only check that. Like this:

  dependencies:
- { role: example-role, when: "'hostname' in ansible_hostname|lower" }
like image 65
Dean Fenster Avatar answered Oct 20 '22 09:10

Dean Fenster