Traditional programming language usually uses the if-else statement when more than one outcome is expected. In Ansible when statement is used instead to determine the outcome of a variable. So instead of using the if-else statement, you can use when statement. The syntax is as given below.
- name: install Apache Web-Server
- name: Install Apache on CentOS Server
yum: name=httpd state=present
when: ansible_os_family == "RedHat"