Try something like:
- hosts: all
remote_user: root
gather_facts: false
tasks:
- name: Check for Python
raw: test -e /usr/bin/python
changed_when: false
failed_when: false
register: check_python
- name: Install Python
raw: yum -y install python
when: check_python.rc != 0
It basically checks I python is already installed. If it hasn't it will install it. The task, in this case, installs python on CentOs or Ubuntu using yum.