- name: 'use pip3'
  set_fact:
    pip_executable_install: pip3
  when: ansible_python.version.major == 3
- name: 'use pip'
  set_fact:
    pip_executable_install: pip
  when: ansible_python.version.major == 2
- name: china mirror pip
  set_fact:
    china_mirror_pip: true
  when: china_mirror
- name: clean pip dir
  become: true
  file:
    path: '{{item}}/.pip'
    state: absent
  when: not china_mirror_pip
  with_items:
    - '{{ansible_user_dir}}'
    - /root
- name: pip dir
  become: true
  file:
    path: '{{item.path}}/.pip'
    state: directory
    owner: '{{item.owner}}'
    group: '{{item.owner}}'
    mode: 0755
  when: china_mirror_pip
  with_items:
    - path: '{{ansible_user_dir}}'
      owner: '{{ansible_user_id}}'
    - path: /root
      owner: root
- name: pip conf for china mirror
  become: true
  copy:
    content: |
      [global]
      index-url = https://mirrors.aliyun.com/pypi/simple/
      [install]
      trusted-host = mirrors.aliyun.com
    dest: '{{item.path}}/.pip/pip.conf'
    owner: '{{item.owner}}'
    group: '{{item.owner}}'
    mode: 0644
  when: china_mirror_pip
  with_items:
    - path: '{{ansible_user_dir}}'
      owner: '{{ansible_user_id}}'
    - path: /root
      owner: root
- name: clean easy install
  become: true
  file:
    path: '/usr/local/lib/python{{item}}/dist-packages/easy-install.pth'
    state: absent
  with_items:
    - 2.7
    - 3.5
    - 3.6
    - 3.7
    - 3.8
- name: upgrade pip
  become: true
  pip:
    name: pip
    executable: '{{pip_executable_install}}'
    state: latest
- name: pip package list
  set_fact:
    pip_package_list: 'autopep8'
- name: pip packages
  become: true
  pip:
    name: '{{pip_package_list}}'
