Ansible Tutorial

How to check partial string comparison in ansible?

How to check partial string comparison in ansible?

we can use "in" operator in ansible to check whether one string is matched partially or entirely another string in ansible expressions or conditions.

Lets us see the simple example to find the partial string match in another string using the "in" operator.

- hosts: localhost
  connection: local
  gather_facts: no
  vars:
	string1: "teststring-0"
	string2: "teststring-0-additional-string"

  tasks:
	- name: Checks partial string
  	set_fact:
    	result: "{{ string1 in string2}}"
  	register: result

	- name: Print the var
  	debug:
    	var: result

Output:

$ ansible-playbook test3.yml

PLAY [localhost] ************************************************************************************************************************************************************

TASK [Checks partial string] *********************************************************************************************************************************************************
ok: [localhost]

TASK [Print the var] ********************************************************************************************************************************************************
ok: [localhost] => {
	"result": true
}





Python installation

 Ansible Tutorial

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^