Skip to content

Commit 6d80206

Browse files
committed
Improve git based database role
1 parent cf20df2 commit 6d80206

File tree

4 files changed

+61
-61
lines changed

4 files changed

+61
-61
lines changed

playbooks/deploy.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
(ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.type is defined and ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.type == 'mongo')
2323
) | bool
2424
}}"
25+
snapshots_repository: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.repository is defined and ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.repository }}"
26+
snapshots_path: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.path is defined and ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.path }}"
27+
versions_repository: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.repository is defined and ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.repository }}"
28+
versions_path: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.path is defined and ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.path }}"
29+
2530
- name: Install infrastructure
2631
become: true
2732
tags: [infrastructure]
@@ -57,9 +62,25 @@
5762
when:
5863
- mongo_required
5964

60-
- name: Setup Git-based databases
65+
- name: Setup Git-based versions database
6166
ansible.builtin.include_role:
6267
name: ota/git-database
68+
vars:
69+
ota_git_database_repository: "{{ versions_repository }}"
70+
ota_git_database_directory: "{{ versions_path }}"
71+
ota_git_database_branch: main
72+
when:
73+
- versions_repository and versions_path
74+
75+
- name: Setup Git-based snapshots database
76+
ansible.builtin.include_role:
77+
name: ota/git-database
78+
vars:
79+
ota_git_database_repository: "{{ snapshots_repository }}"
80+
ota_git_database_directory: "{{ snapshots_path }}"
81+
ota_git_database_branch: main
82+
when:
83+
- snapshots_repository and snapshots_path
6384

6485
- name: Setup OTA applications
6586
ansible.builtin.include_role:

roles/ota/git-database/defaults/main.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

roles/ota/git-database/tasks/database.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
---
2-
- name: Setup snapshots git repository
3-
ansible.builtin.include_tasks: database.yml
4-
when: ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.repository is defined
5-
vars:
6-
engine_database_name: snapshots
7-
engine_database_repository: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.repository }}"
8-
engine_database_branch: "{{ ota_database_snapshots_branch }}"
9-
engine_database_directory: /home/{{ ansible_user }}/{{ ota_directory }}/{{ ota_apps_config['@opentermsarchive/engine'].recorder.snapshots.storage.git.path }}
2+
- name: Check if base data has already been obtained from {{ ota_git_database_repository }}
3+
ansible.builtin.git:
4+
repo: "{{ ota_git_database_repository }}"
5+
version: "{{ ota_git_database_branch }}"
6+
dest: "{{ ota_git_database_directory }}"
7+
clone: false
8+
update: false
9+
key_file: /home/{{ ansible_user }}/.ssh/ota-github-bot-key
10+
# the `before` property of the return value can tell us if the repository has been cloned already or not,
11+
# see <https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html#return-values>
12+
register: existing_repository
1013

11-
- name: Setup versions git repository
12-
ansible.builtin.include_tasks: database.yml
13-
when: ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.repository is defined
14-
vars:
15-
engine_database_name: versions
16-
engine_database_repository: "{{ ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.repository }}"
17-
engine_database_branch: "{{ ota_database_versions_branch }}"
18-
engine_database_directory: /home/{{ ansible_user }}/{{ ota_directory }}/{{ ota_apps_config['@opentermsarchive/engine'].recorder.versions.storage.git.path }}
14+
- name: Obtain initial data from branch {{ ota_git_database_branch }} of {{ ota_git_database_repository }}
15+
ansible.builtin.git:
16+
repo: "{{ ota_git_database_repository }}"
17+
version: "{{ ota_git_database_branch }}"
18+
dest: "{{ ota_git_database_directory }}"
19+
key_file: /home/{{ ansible_user }}/.ssh/ota-github-bot-key
20+
when: existing_repository.before is defined and not existing_repository.before # if existing_repository.before is null, then the repository is new
21+
22+
- name: Configure {{ ota_git_database_directory }} repository to use the GitHub Bot SSH Key
23+
community.general.git_config:
24+
name: core.sshCommand
25+
value: ssh -i '/home/{{ ansible_user }}/.ssh/ota-github-bot-key'
26+
scope: local
27+
repo: "{{ ota_git_database_directory }}"
28+
29+
- name: Remove existing locks in {{ ota_git_database_directory }}
30+
ansible.builtin.file:
31+
path: "{{ ota_git_database_directory }}/.git/index.lock"
32+
state: absent
33+
34+
- name: Get latest data from {{ ota_git_database_repository }}
35+
ansible.builtin.git:
36+
repo: "{{ ota_git_database_repository }}"
37+
version: "{{ ota_git_database_branch }}"
38+
dest: "{{ ota_git_database_directory }}"
39+
update: true
40+
force: true # discard any modified files
41+
key_file: /home/{{ ansible_user }}/.ssh/ota-github-bot-key

0 commit comments

Comments
 (0)