---
# nbde_server_deploy_keys basically deploys keys that exist locally in
# nbde_server_keys_dir to tang servers. Within nbde_server_keys_dir, keys
# placed in the top level domain are deployed to every host, while keys
# inside folders named after hosts are deployed to these specific hosts.

- name: Test nbde_server_deploy_keys
  hosts: all

  vars:
    nbde_server_keys_dir: /tmp/.nbde_server_keys_dir

  tasks:
    - name: Ensure we have keys
      import_role:
        name: redhat.rhel_system_roles.nbde_server

    - name: Clean up nbde_server_keys_dir
      file:
        path: "{{ nbde_server_keys_dir }}"
        state: absent

    - name: Fetch the keys from every host
      import_role:
        name: redhat.rhel_system_roles.nbde_server
      vars:
        nbde_server_fetch_keys: true
        nbde_server_deploy_keys: false

    - name: Gather keys before redeploy
      find:
        paths: "{{ __nbde_server_keydir }}"
        hidden: true
        patterns:
          - "*.jwk"
          - ".*.jwk"
      register: nbde_server_keys_before_redeploy

    - name: Redeploy these same keys
      import_role:
        name: redhat.rhel_system_roles.nbde_server
      vars:
        nbde_server_fetch_keys: false
        nbde_server_deploy_keys: true

    - name: Gather keys after redeploy
      find:
        paths: "{{ __nbde_server_keydir }}"
        hidden: true
        patterns:
          - "*.jwk"
          - ".*.jwk"
      register: nbde_server_keys_after_redeploy

    - name: Verify the keys are the same
      assert:
        that: >
          nbde_server_keys_before_redeploy.files
          == nbde_server_keys_after_redeploy.files

# vim:set ts=2 sw=2 et:
