---
- block:
  - name: Display the invocation environment
    shell: >
      ./algo-showenv.sh \
        'algo_provider "{{ algo_provider }}"' \
        {% if ipsec_enabled %}
        'algo_ondemand_cellular "{{ algo_ondemand_cellular }}"' \
        'algo_ondemand_wifi "{{ algo_ondemand_wifi }}"' \
        'algo_ondemand_wifi_exclude "{{ algo_ondemand_wifi_exclude }}"' \
        {% endif %}
        'algo_dns_adblocking "{{ algo_dns_adblocking }}"' \
        'algo_ssh_tunneling "{{ algo_ssh_tunneling }}"' \
        'wireguard_enabled "{{ wireguard_enabled }}"' \
        'dns_encryption "{{ dns_encryption }}"' \
        > /dev/tty
    tags: debug

  - name: Install the requirements
    pip:
      state: latest
      name:
        - pyOpenSSL
        - jinja2==2.8
        - segno
    tags:
      - always
      - skip_ansible_lint
  delegate_to: localhost
  become: false

- name: Generate the SSH private key
  openssl_privatekey:
    path: "{{ SSH_keys.private }}"
    size: 2048
    mode: "0600"
    type: RSA
  when: algo_provider != "local"

- name: Generate the SSH public key
  openssl_publickey:
    path: "{{ SSH_keys.public }}"
    privatekey_path: "{{ SSH_keys.private }}"
    format: OpenSSH
  when: algo_provider != "local"
