---
- name: install global python pips
  pip:
    name: "{{ global_pip_to_install }}"
    extra_args: --user

- name: uninstall global python pips
  pip:
    name: "{{ global_pip_to_uninstall }}"
    state: absent

- name: ensure global python pips are in path
  lineinfile:
    path: "{{ dotfile }}"
    state: present
    line: "[[ \":$PATH:\" != *\":$HOME/.local/bin:\"* ]] && PATH=\"$HOME/.local/bin:$PATH\" || true"

- set_fact:
    execute_virtualenv: "{{ virtualenv_pip_to_install | length > 0 }}"

- block:
  - name: install virtualenv python pips
    pip:
      name: "{{ virtualenv_pip_to_install }}"
      virtualenv: "{{ virtualenv_path }}"

  - name: uninstall virtualenv python pips
    pip:
      name: "{{ virtualenv_pip_to_uninstall }}"
      virtualenv: "{{ virtualenv_path }}"

  - name: ensure activating virtualenv when loading shell
    lineinfile:
      path: "{{ dotfile }}"
      state: present
      line: "source {{ virtualenv_path }}/bin/activate || true"

  when: execute_virtualenv

---
- name: install global python pips
  pip:
    name: "{{ global_pip_to_install }}"
    extra_args: --user
  when: global_pip_to_install|length > 0

- name: uninstall global python pips
  pip:
    name: "{{ global_pip_to_uninstall }}"
    state: absent
  when: global_pip_to_uninstall|length > 0

- name: ensure global python pips are in path
  lineinfile:
    path: "{{ dotfile }}"
    state: present
    line: "[[ \":$PATH:\" != *\":$HOME/.local/bin:\"* ]] && PATH=\"$HOME/.local/bin:$PATH\" || true"

- set_fact:
    execute_virtualenv: "{{ virtualenv_pip_to_install | length > 0 }}"

- block:
  - name: install virtualenv python pips
    pip:
      name: "{{ virtualenv_pip_to_install }}"
      virtualenv: "{{ virtualenv_path }}"
    when: virtualenv_pip_to_install|length > 0

  - name: uninstall virtualenv python pips
    pip:
      name: "{{ virtualenv_pip_to_uninstall }}"
      virtualenv: "{{ virtualenv_path }}"
    when: virtualenv_pip_to_uninstall|length > 0

  - name: ensure activating virtualenv when loading shell
    lineinfile:
      path: "{{ dotfile }}"
      state: present
      line: "source {{ virtualenv_path }}/bin/activate || true"

  when: execute_virtualenv

Add protection for when not specifying pips to install/delete
Add protection for when not specifying pips to install/delete

The ansible run may fail if there are no pip packages to
install/uninstall.

I believe this error may only actually occur on certain ansible
versions. But it's easy to fix.
