[linux] Run an Ansible task only when the variable contains a specific string

This works for me in Ansible 2.9:

variable1 = www.example.com. 
variable2 = www.example.org. 

when: ".com" in variable1

and for not:

when: not ".com" in variable2

Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to conditional

Pandas/Python: Set value of one column based on value in another column Run an Ansible task only when the variable contains a specific string (Excel) Conditional Formatting based on Adjacent Cell Value Laravel Checking If a Record Exists Multiple conditions in if statement shell script The condition has length > 1 and only the first element will be used Creating a new column based on if-elif-else condition How to conditional format based on multiple specific text in Excel Using SUMIFS with multiple AND OR conditions Replacing Numpy elements if condition is met

Examples related to ansible

Specifying ssh key in ansible playbook file Ansible: how to get output to display How to do multiline shell script in Ansible Accessing inventory host variable in Ansible playbook Ansible: get current target host's IP address Ansible Ignore errors in tasks and fail at end of the playbook if any tasks had errors Ansible: How to delete files and folders inside a directory? How to pass a user / password in ansible command How to test that a registered variable is not empty? Copy multiple files with Ansible

Examples related to ansible-playbook

Ansible Ignore errors in tasks and fail at end of the playbook if any tasks had errors Ansible: create a user with sudo privileges Run an Ansible task only when the variable contains a specific string Ansible: Store command's stdout in new variable? Checking for multiple conditions using "when" on single task in ansible how to define ssh private key for servers fetched by dynamic inventory in files Override hosts variable of Ansible playbook from the command line Proper way to concatenate variable strings How can I pass variable to ansible playbook in the command line? How to run a task when variable is undefined in ansible?

Examples related to ansible-2.x

Accessing inventory host variable in Ansible playbook Run an Ansible task only when the variable contains a specific string Ansible: copy a directory content to another directory Ansible - Use default if a variable is not defined