---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

####################################################################
# WARNING: These are designed specifically for Ansible tests       #
# and should not be used as examples of how to write Ansible roles #
####################################################################

- name: Declare global variables
  set_fact:
    signing_key: '{{ remote_tmp_dir }}/id_key'
    public_key: '{{ remote_tmp_dir }}/id_key.pub'
    certificate_path: '{{ remote_tmp_dir }}/id_cert'

- name: Generate keypair
  openssh_keypair:
    path: "{{ signing_key }}"
    type: rsa
    size: 1024

- block:
    - name: Import idempotency tests
      import_tasks: ../tests/idempotency.yml

    - name: Import key_idempotency tests
      import_tasks: ../tests/key_idempotency.yml

    - name: Import options tests
      import_tasks: ../tests/options_idempotency.yml

    - name: Import regenerate tests
      import_tasks: ../tests/regenerate.yml

    - name: Import remove tests
      import_tasks: ../tests/remove.yml
  when: not (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "6")

- name: Import ssh-agent tests
  import_tasks: ../tests/ssh-agent.yml
  when: openssh_version is version("7.6",">=")

- name: Remove keypair
  openssh_keypair:
    path: "{{ signing_key }}"
    state: absent
