|
1 | 1 | ---
|
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 |
10 | 13 |
|
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