copy-deployment-configs.yaml

Overview

This Ansible playbook manages deployment configurations by conditionally generating and updating several key configuration files within a specified directory (BK_DIR). It primarily focuses on verifying the presence of a JSON configuration file, setting a fact accordingly, and templating configuration files such as Docker Compose, Aerospike, and Logrotate based on deployment conditions and upgrade flags.

The file automates and controls deployment configuration updates to ensure that necessary files are created or refreshed only under specific conditions, such as during full deployments or partial upgrades.

Tasks and Their Functionality

1. Check if bk_set.json Exists

- name: Check if bk_set.json exists
  ansible.builtin.stat:
    path: "{{ BK_DIR }}/bk-configs/bk_set.json"
  register: bk_set_file_stat

2. Set HAS_BK_SET_FILE Fact

- name: Set HAS_BK_SET_FILE fact
  ansible.builtin.set_fact:
    HAS_BK_SET_FILE: "{{ bk_set_file_stat.stat.exists }}"

3. Production Compose File Generation

- name: Production compose
  ansible.builtin.template:
    src: templates/docker-compose.j2
    dest: "{{ BK_DIR }}/docker-compose.yaml"
    mode: "0644"
  register: compose
  when: not FAST_UPDATE or (UPGRADE is defined and ('compose' in UPGRADE or 'node' in UPGRADE or 'compose-add' in UPGRADE))

4. Aerospike Configuration Generation

- name: Aerospike configuration
  ansible.builtin.template:
    src: templates/aerospike.conf.j2
    dest: "{{ BK_DIR }}/aerospike-config/aerospike.conf"
    mode: "0644"
  register: aerospike
  when: not FAST_UPDATE or (UPGRADE is defined and 'aerospike' in UPGRADE)

5. Log Rotate Configuration Generation

- name: Log rotate configuration
  ansible.builtin.template:
    src: templates/logrotate.j2
    dest: "{{ BK_DIR }}/logrotate.sh"
    mode: "0755"
  register: logrotate
  when: not FAST_UPDATE or (UPGRADE is defined and 'logrotate' in UPGRADE)

Implementation Details and Algorithms

Interaction with Other System Components


Visual Diagram: Flowchart of Main Tasks and Their Conditional Execution

flowchart TD
A[Check bk_set.json Exists] --> B[Set HAS_BK_SET_FILE Fact]
B --> C{Compose Generation?}
C -->|Yes| D[Generate docker-compose.yaml]
C -->|No| E[Skip Compose]
B --> F{Aerospike Config?}
F -->|Yes| G[Generate aerospike.conf]
F -->|No| H[Skip Aerospike]
B --> I{Logrotate Config?}
I -->|Yes| J[Generate logrotate.sh]
I -->|No| K[Skip Logrotate]
%% Conditions
C:::cond
F:::cond
I:::cond
classDef cond fill:#f9f,stroke:#333,stroke-width:2px

This flowchart illustrates the sequence starting from the file existence check, setting facts, and then branching into conditional generation of the three configuration files based on flags and upgrade conditions.