- name: Run Pytest
  hosts: tester
  gather_facts: yes
  any_errors_fatal: true
  vars:
      repo_folder: 'pytest-repo/'
      pytest_output_filename: 'pytest-results-{{ ansible_date_time.epoch }}.xml'
  tasks:
      - name: Install pip
        become: yes
        easy_install:
          name: pip
          state: latest

      - name: intall pytest via pip
        pip:
          name: pytest
          state: present
        become: true

      - name: Install packages
        become: true
        package:
            name:
              - git
            state: latest

      - name: Clean old files
        file:
            path: "{{ item }}"
            state: absent
        with_items:
            - "{{ repo_folder }}"
            - "{{ pytest_output_filename }}"

      - name: Cloning git repo
        shell: |
            export GIT_SSL_NO_VERIFY=true
            git clone {{ test.repo }} {{ repo_folder }}
        tags: skip_ansible_lint

      - name: Execute test
        ignore_errors: true
        shell: pytest -v {{ repo_folder }}{{ test.file }}
               --junitxml={{ pytest_output_filename }} 2>&1 --tb=no -r fp
        when: test.run|default(False)
        register: pytest_execution

      - name: Fetch JUnit XML results file
        fetch:
            src: "{{ pytest_output_filename }}"
            dest: "{{ inventory_dir }}/pytest_results/{{ pytest_output_filename }}"
            flat: yes
            fail_on_missing: yes

- name: Run Pytest
  hosts: tester
  gather_facts: yes
  any_errors_fatal: true
  vars:
      repo_folder: 'pytest-repo/'
      pytest_output_filename: 'pytest-results-{{ ansible_date_time.epoch }}.xml'
  tasks:
      - name: intall python-pip
        package:
          name: python-pip
          state: present
        when: ansible_python_version is version('3', '<')

      - name: intall python3-pip
        package:
          name: python3-pip
          state: present
        when: ansible_python_version  is version('3', '>=')
        become: true

      - name: intall pytest via pip
        pip:
          name: pytest
          state: present
        become: true

      - name: Install packages
        become: true
        package:
            name:
              - git
            state: latest

      - name: Clean old files
        file:
            path: "{{ item }}"
            state: absent
        with_items:
            - "{{ repo_folder }}"
            - "{{ pytest_output_filename }}"

      - name: Cloning git repo
        shell: |
            export GIT_SSL_NO_VERIFY=true
            git clone {{ test.repo }} {{ repo_folder }}
        tags: skip_ansible_lint

      - name: Execute test
        ignore_errors: true
        shell: pytest -v {{ repo_folder }}{{ test.file }}
               --junitxml={{ pytest_output_filename }} 2>&1 --tb=no -r fp
        when: test.run|default(False)
        register: pytest_execution

      - name: Fetch JUnit XML results file
        fetch:
            src: "{{ pytest_output_filename }}"
            dest: "{{ inventory_dir }}/pytest_results/{{ pytest_output_filename }}"
            flat: yes
            fail_on_missing: yes

Revert from easy_install to package install for python-pip
Revert from easy_install to package install for python-pip

according to presenting packages in downstream and outdated
way - switch to package based installation

Change-Id: I13fe698a1f80353b210813ba9969130fd2a690ba
