# issue #109: ensure that any 'ansible' module or package on the remote machine
# does not conflict with operation.

- name: regression/issue_109__target_has_old_ansible_installed.yml
  hosts: test-targets
  gather_facts: true
  tasks:
    - meta: end_play
      when:
        - ansible_version_major_minor is version('2.6', '<', strict=True)

    - name: Copy the naughty ansible into place
      copy:
        dest: "{{ansible_user_dir}}/ansible.py"
        src: ansible.py

    # Restart the connection.
    - meta: reset_connection

    - custom_python_detect_environment:
      register: env

    - name: Verify interpreter config would actually trigger the bug
      assert:
        that:
          - env.cwd == ansible_user_dir
          - not env.mitogen_loaded
            or (env.python_path | select('eq', '') | length == 1)
        fail_msg: |
          ansible_user_dir={{ ansible_user_dir }}
          env={{ env }}

    - name: Run some new-style from ansible.module_utils... modules
      stat:
        path: /
  tags:
    - issue_109
