ansible_drone/tasks/drone-database.yml

108 lines
3.1 KiB
YAML
Raw Normal View History

2019-06-15 17:55:37 +02:00
---
2021-02-21 00:05:41 +01:00
- name: Creates postgres backup directory
2019-06-15 17:55:37 +02:00
file:
2021-02-21 00:05:41 +01:00
path: "{{ drone_postgres_backup_dir }}/backup"
2019-06-15 17:55:37 +02:00
state: directory
2021-02-21 00:05:41 +01:00
owner: root
group: root
mode: 0755
register: drone_postgres_backup_dir_state
when: drone_database_driver == "postgres"
tags:
- postgres
- database
- name: Creates postgres recovery directory
file:
path: "{{ drone_postgres_backup_dir }}/restore"
state: directory
owner: root
group: root
2019-06-15 17:55:37 +02:00
mode: 0755
2019-06-16 08:19:20 +02:00
when: drone_database_driver == "postgres"
2019-06-15 17:55:37 +02:00
tags:
- postgres
2019-06-16 08:19:20 +02:00
- database
2019-06-15 17:55:37 +02:00
- name: start postgres for drone ci
docker_container:
name: postgres
image: postgres:11
state: started
restart_policy: always
ports:
- "5432:5432"
volumes:
2021-02-21 00:05:41 +01:00
- "postgres_data:/var/lib/postgresql/data"
- "{{ drone_postgres_backup_dir }}/backup:/var/lib/pgbackup"
- "{{ drone_postgres_backup_dir }}/restore:/docker-entrypoint-initdb.d:ro"
2019-06-15 17:55:37 +02:00
env:
2019-06-16 08:19:20 +02:00
POSTGRES_PASSWORD: "{{ drone_postgres_password }}"
POSTGRES_USER: "{{ drone_postgres_user }}"
POSTGRES_DB: "{{ drone_postgres_db }}"
2021-02-21 00:05:41 +01:00
when: drone_postgres_backup_dir_state is defined and drone_postgres_backup_dir_state.changed or
2019-06-16 08:19:20 +02:00
drone_database_driver == "postgres"
2019-06-15 17:55:37 +02:00
tags:
- postgres
2019-06-16 08:19:20 +02:00
- database
- skip_ansible_lint
2019-06-16 08:19:20 +02:00
2021-02-21 00:05:41 +01:00
- name: create backup service for drone postgres database
template:
src: "templates/{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: "{{ item.mode }}"
vars:
backup_frequency: "{{ drone_postgres_backup_frequency|default('daily') }}"
backup_path: "{{ drone_postgres_backup_dir }}"
with_items:
- {src: postgres_backup.service.j2, dest: /etc/systemd/system/postgres_backup.service, mode: "0644"}
- {src: postgres_backup.timer.j2, dest: /etc/systemd/system/postgres_backup.timer, mode: "0644"}
- {src: pg_backup.sh.j2, dest: /usr/local/bin/pg_backup.sh, mode: "0755"}
notify: reload postgres_backup service
when: drone_postgres_backup_dir_state is defined and drone_postgres_backup_dir_state.changed or
drone_database_driver == "postgres"
tags:
- postgres
- database
- name: ensure backup service for drone postgres database is enabled
systemd:
name: postgres_backup.timer
enabled: yes
2019-06-16 08:19:20 +02:00
- name: Creates mysql directory
file:
path: "{{ drone_mysql_data_dir }}"
state: directory
mode: 0755
register: drone_mysql_data_dir
when: drone_database_driver == "mysql"
tags:
- mysql
- database
- name: start mysql for drone ci
docker_container:
name: mysql
image: mysql:5.7
state: started
restart_policy: always
ports:
- "3306:3306"
volumes:
- "{{ drone_mysql_data_dir }}:/var/lib/mysqlql/data"
env:
MYSQL_PASSWORD: "{{ drone_mysql_password }}"
MYSQL_USER: "{{ drone_mysql_user }}"
MYSQL_DATABASE: "{{ drone_mysql_db }}"
MYSQL_ROOT_PASSWORD: "{{ drone_mysql_password }}"
when: drone_mysql_data_dir is defined and drone_mysql_data_dir.changed or
drone_database_driver == "mysql"
tags:
- mysql
- database
- skip_ansible_lint