- name: Process Python 2 for backward compatibility
  block:
    - name: Install python2 pip
      package:
        name: 
          - python-pip
          - python-netaddr
        state: latest

    - name: Install dnslookup library for python2
      pip:
        name:
          - dnspython==1.16.0
        executable: pip2
  when: ansible_python.version.major|int == 2

- name: Process Python 3 as interpreter
  block:
    - name: Install required Python packages
      package:
        name: python3
        state: latest

    - name: Get Python 3 path
      shell: "which python3"
      register: python3_abs_path

    - name: Get Python 3 version
      shell: 'python3 -c "import platform; print(platform.python_version())"'
      register: python3_version

    - name: Set Python 3 interpreter for deployment
      set_fact:
        ansible_python_interpreter: "{{ python3_abs_path.stdout }}"

    - name: Set Python 3 interpreter version
      set_fact:
        ansible_python_version: "{{ python3_version.stdout }}"
  when: ansible_python.version.major| int == 2

- name: Install python3 setup accessories
  block:
    - name: Python3 setup tools
      package:
        name: python3-setuptools
        state: latest
    
    - name: PIP
      package:
        name: python3-pip
        state: latest
