
# These tests don't run on vanilla because ssh-askpass wants to run for
# whatever reason.

- name: integration/ssh/variables.yml
  hosts: test-targets[0]
  connection: local
  vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    # ControlMaster has the effect of caching the previous auth to the same
    # account, so disable it. Can't disable with ControlMaster no since that
    # already appears on command line, so override ControlPath with junk.
    ansible_ssh_common_args: |
      -o "ControlPath /tmp/mitogen-ansible-test-{{18446744073709551615|random}}"

  tasks:
    - include_tasks: ../_mitogen_only.yml

    - name: ansible_user, ansible_ssh_private_key_file
      shell: >
        ANSIBLE_ANY_ERRORS_FATAL=false
        ANSIBLE_CALLBACK_RESULT_FORMAT=json
        ANSIBLE_LOAD_CALLBACK_PLUGINS=false
        ANSIBLE_STRATEGY=mitogen_linear
        ANSIBLE_SSH_ARGS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
        ANSIBLE_VERBOSITY="{{ ansible_verbosity }}"
        ansible -m shell -a whoami
        {% for inv in ansible_inventory_sources %}
        -i "{{ inv }}"
        {% endfor %}
        test-targets
        -e ansible_user=mitogen__has_sudo_pubkey
        -e ansible_ssh_private_key_file=../data/docker/mitogen__has_sudo_pubkey.key
      args:
        chdir: ../..
      register: out
      changed_when: false

    - name: ansible_user, wrong ansible_ssh_private_key_file
      shell: >
        ANSIBLE_ANY_ERRORS_FATAL=false
        ANSIBLE_CALLBACK_RESULT_FORMAT=json
        ANSIBLE_LOAD_CALLBACK_PLUGINS=false
        ANSIBLE_STRATEGY=mitogen_linear
        ANSIBLE_SSH_ARGS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
        ANSIBLE_VERBOSITY="{{ ansible_verbosity }}"
        ansible -m shell -a whoami
        {% for inv in ansible_inventory_sources %}
        -i "{{ inv }}"
        {% endfor %}
        test-targets
        -e ansible_user=mitogen__has_sudo
        -e ansible_ssh_private_key_file=/dev/null
        -e ansible_python_interpreter=python3000
      args:
        chdir: ../..
      register: out
      changed_when: false
      ignore_errors: true

    - assert:
        that:
          - out.rc == 4  # ansible.executor.task_queue_manager.TaskQueueManager.RUN_UNREACHABLE_HOSTS
        fail_msg: |
          out={{ out }}
  tags:
    - mitogen_only
