---
# 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: "({{ backend }}) Generate key"
  openssh_keypair:
    path: '{{ remote_tmp_dir }}/removed'
    backend: "{{ backend }}"
    state: present

- name: "({{ backend }}) Generate key (idempotency)"
  openssh_keypair:
    path: '{{ remote_tmp_dir }}/removed'
    backend: "{{ backend }}"
    state: present

- name: "({{ backend }}) Remove key"
  openssh_keypair:
    state: absent
    path: '{{ remote_tmp_dir }}/removed'
    backend: "{{ backend }}"

- name: "({{ backend }}) Remove key (idempotency)"
  openssh_keypair:
    state: absent
    path: '{{ remote_tmp_dir }}/removed'
    backend: "{{ backend }}"

- name: "({{ backend }}) Check private key status"
  stat:
    path: '{{ remote_tmp_dir }}/removed'
  register: removed_private_key

- name: "({{ backend }}) Check public key status"
  stat:
    path: '{{ remote_tmp_dir }}/removed.pub'
  register: removed_public_key

- name: "({{ backend }}) Assert key pair files are removed"
  assert:
    that:
      - not removed_private_key.stat.exists
      - not removed_public_key.stat.exists
