
Customization from a settings.yaml file were not effective because we were not retrieving them again. Change-Id: Ia82ab96d02ccc84bdf506d9546c50d49d60f8915
97 lines
3.4 KiB
YAML
97 lines
3.4 KiB
YAML
---
|
|
# Copyright (c) 2019 Red Hat, Inc.
|
|
#
|
|
# This file is part of ARA Records Ansible.
|
|
#
|
|
# ARA Records Ansible is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# ARA Records Ansible is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with ARA Records Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
- name: Verify if a configuration file exists
|
|
stat:
|
|
path: "{{ ara_api_settings }}"
|
|
register: settings_stat
|
|
|
|
# If no secret key has been provided and this isn't the first time we are
|
|
# running, recover the secret key from the existing configuration file.
|
|
- when:
|
|
- ara_api_secret_key is none
|
|
- settings_stat.stat.exists
|
|
block:
|
|
- name: Read the existing configuration file
|
|
command: cat "{{ ara_api_settings }}"
|
|
changed_when: false
|
|
no_log: yes
|
|
register: settings_contents
|
|
|
|
- name: Recover existing secret key
|
|
vars:
|
|
config: "{{ settings_contents.stdout | from_yaml }}"
|
|
set_fact:
|
|
ara_api_secret_key: "{{ config[ara_api_env]['SECRET_KEY'] }}"
|
|
no_log: yes
|
|
|
|
# If no secret key has been provided and this is the first time we are
|
|
# running, generate a new random secret key that will be persisted in the
|
|
# configuration file.
|
|
- when:
|
|
- ara_api_secret_key is none
|
|
- not settings_stat.stat.exists
|
|
block:
|
|
- name: Generate a random secret key
|
|
environment:
|
|
PATH: "{{ path_with_virtualenv | default(omit) }}"
|
|
command: python3 -c "from django.utils.crypto import get_random_string; print(get_random_string(length=50))"
|
|
no_log: yes
|
|
register: generated_key
|
|
|
|
- name: Set ara_api_secret_key
|
|
set_fact:
|
|
ara_api_secret_key: "{{ generated_key.stdout }}"
|
|
no_log: yes
|
|
|
|
# Put configuration in a format we can write to a file
|
|
- name: Reconcile configuration
|
|
vars:
|
|
reconciled_configuration:
|
|
ALLOWED_HOSTS: "{{ ara_api_allowed_hosts }}"
|
|
BASE_DIR: "{{ ara_api_base_dir }}"
|
|
CORS_ORIGIN_ALLOW_ALL: "{{ ara_api_cors_origin_allow_all }}"
|
|
CORS_ORIGIN_WHITELIST: "{{ ara_api_cors_origin_whitelist }}"
|
|
DATABASE_ENGINE: "{{ ara_api_database_engine }}"
|
|
DATABASE_NAME: "{{ ara_api_database_name }}"
|
|
DATABASE_USER: "{{ ara_api_database_user }}"
|
|
DATABASE_PASSWORD: "{{ ara_api_database_password }}"
|
|
DATABASE_HOST: "{{ ara_api_database_host }}"
|
|
DATABASE_PORT: "{{ ara_api_database_port }}"
|
|
DEBUG: "{{ ara_api_debug }}"
|
|
LOGGING: "{{ ara_api_logging }}"
|
|
LOG_LEVEL: "{{ ara_api_log_level }}"
|
|
SECRET_KEY: "{{ ara_api_secret_key }}"
|
|
READ_LOGIN_REQUIRED: "{{ ara_api_read_login_required }}"
|
|
WRITE_LOGIN_REQUIRED: "{{ ara_api_write_login_required }}"
|
|
set_fact:
|
|
ara_api_configuration: "{'{{ ara_api_env }}': {{ reconciled_configuration }} }"
|
|
no_log: yes
|
|
|
|
- name: Set up the ARA API configuration file
|
|
copy:
|
|
content: |
|
|
---
|
|
# Managed by the ara Ansible role
|
|
{{ ara_api_configuration | to_nice_yaml(indent=2) }}
|
|
dest: "{{ ara_api_settings }}"
|
|
mode: 0750
|
|
notify:
|
|
- restart ara-api
|
|
no_log: yes
|