# issue #152 (b): local connections were not receiving
# ansible_python_interpreter treatment, breaking virtualenvs. Verify this is
# fixed by writing out a wrapper script that sets an environment variable we
# can test for.

- name: regression/issue_152__local_action_wrong_interpreter.yml
  hosts: test-targets[0]
  connection: local
  tasks:
    - name: Create /tmp/issue_152_interpreter.sh
      vars:
        ansible_python_interpreter: "{{ ansible_playbook_python }}"
      copy:
        dest: /tmp/issue_152_interpreter.sh
        mode: u+x
        content: |
          #!/bin/bash
          export CUSTOM_INTERPRETER=1
          exec python "$@"

    - custom_python_detect_environment:
      vars:
        ansible_python_interpreter: /tmp/issue_152_interpreter.sh
      register: out

    - assert:
        that:
          - out.env.CUSTOM_INTERPRETER == "1"
        fail_msg: |
          out={{ out }}

    - name: Cleanup /tmp/issue_152_interpreter.sh
      vars:
        ansible_python_interpreter: "{{ ansible_playbook_python }}"
      file:
        path: /tmp/issue_152_interpreter.sh
        state: absent
  tags:
    - issue_152
