Hi@akhtar,
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
hosts: all
tasks:
- name: Install Apache on CentOS Server
yum: name=httpd state=present
become: yes
when: ansible_os_family == "RedHat"