---
# Check {{ generated_certs_dir }} for session_secret and oauth_secret
- name: Checking for session_secret
  stat:
    path: "{{generated_certs_dir}}/session_secret"
    get_checksum: false
    get_attributes: false
    get_mime: false
  register: session_secret_file

- name: Checking for oauth_secret
  stat:
    path: "{{generated_certs_dir}}/oauth_secret"
    get_checksum: false
    get_attributes: false
    get_mime: false
  register: oauth_secret_file

# gen session_secret if necessary
- name: Generate session secret
  copy:
    content: "{{ 32 | lib_utils_oo_random_word }}"
    dest: "{{ generated_certs_dir }}/session_secret"
  when: not session_secret_file.stat.exists or session_secret_file.stat.size > 50

# gen oauth_secret if necessary
- name: Generate oauth secret
  copy:
    content: "{{ 64 | lib_utils_oo_random_word }}"
    dest: "{{ generated_certs_dir }}/oauth_secret"
  when:
    - not oauth_secret_file.stat.exists
