using regex in jinja 2 for ansible playbooks

后端 未结 7 2057
北海茫月
北海茫月 2020-12-31 06:37

HI i am new to jinja2 and trying to use regular expression as shown below

{% if ansible_hostname == \'uat\' %}
   {% set server = \'thinkingmonster.com\' %}
         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 07:04

    This is rather ugly, but it works as of 1.6.

    {% if server|regex_replace('.*thinking.*','matched') == 'matched' %}
      {% set ssl_certificate = 'akash' %}
    
    {% elif server|regex_replace('.*sleeping.*','matched') == 'matched' %}
       {% set ssl_certificate = 'akashthakur' %}
    {% endif %}
    

提交回复
热议问题