---
- name: Install Packages | apt | build dependencies
  apt:
    state: latest
    pkg: "{{ item }}"
  with_items: python_build_dependencies
  when: python_build_dependencies
  tags:
    - software-installation
    - using-apt
    - python

- name: Install Packages | apt
  apt:
    state: latest
    pkg: "{{ item }}"
  with_items:
    - python-dev
    - python-setuptools
    - python-pip
    - python3
    - python3-dev
    - python3-setuptools
  tags:
    - software-installation
    - using-apt
    - python

- name: "Install Packages | pip | {{ python_packages }}"
  pip:
    executable: "{{ python_pip_executable }}"
    state: latest
    name: "{{ item }}"
  with_items: python_packages
  when: python_packages
  tags:
    - software-installation
    - using-pip
    - python

- name: Install Packages | pip | requirements file
  pip:
    executable: "{{ python_pip_executable }}"
    state: latest
    requirements: "{{ python_requirements_file }}"
  when: python_requirements_file != 'omit'
  tags:
    - software-installation
    - using-pip
    - python

---
- name: Install Packages | apt | build dependencies
  apt:
    state: latest
    pkg: "{{ item }}"
  with_items: python_build_dependencies
  when: python_build_dependencies
  tags:
    - software-installation
    - using-apt
    - python

- name: Install Packages | apt
  apt:
    state: latest
    pkg: "{{ item }}"
  with_items:
    - python-dev
    - python-setuptools
    - python-pip
    - python3
    - python3-dev
    - python3-setuptools
  tags:
    - software-installation
    - using-apt
    - python

- name: "Install Packages | pip | {{ python_packages }}"
  pip:
    executable: "{{ python_pip_executable }}"
    state: "{% if item is 'ansible' %}present{% else %}latest{% endif %}
    name: "{{ item }}"
  with_items: python_packages
  when: python_packages
  tags:
    - software-installation
    - using-pip
    - python

- name: Install Packages | pip | requirements file
  pip:
    executable: "{{ python_pip_executable }}"
    state: latest
    requirements: "{{ python_requirements_file }}"
  when: python_requirements_file != 'omit'
  tags:
    - software-installation
    - using-pip
    - python

Make ansible-python play nice with version-pinning
Make ansible-python play nice with version-pinning

If Ansible is already installed, this will not upgrade it. Otherwise, it will still install the latest version.

Any forged systems will have ansible installed already.