Add temporary devops rework
This commit is contained in:
parent
cc46c0e89e
commit
d2e59d6bbb
8
devops/README.md
Normal file
8
devops/README.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Ansible
|
||||||
|
|
||||||
|
Catalogue of Ansible playbooks and helper scripts for server management
|
||||||
|
|
||||||
|
## Gitlab backups
|
||||||
|
|
||||||
|
#### Test ansible scripts locally
|
||||||
|
ansible-playbook playbook.yml --connection=local --inventory=127.0.0.1, --limit 127.0.0.1
|
5
devops/backup.yml
Normal file
5
devops/backup.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- backup
|
29
devops/backup/.travis.yml
Normal file
29
devops/backup/.travis.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
language: python
|
||||||
|
python: "2.7"
|
||||||
|
|
||||||
|
# Use the new container infrastructure
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
# Install ansible
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python-pip
|
||||||
|
|
||||||
|
install:
|
||||||
|
# Install ansible
|
||||||
|
- pip install ansible
|
||||||
|
|
||||||
|
# Check ansible version
|
||||||
|
- ansible --version
|
||||||
|
|
||||||
|
# Create ansible.cfg with correct roles_path
|
||||||
|
- printf '[defaults]\nroles_path=../' >ansible.cfg
|
||||||
|
|
||||||
|
script:
|
||||||
|
# Basic role syntax check
|
||||||
|
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
38
devops/backup/README.md
Normal file
38
devops/backup/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
|
||||||
|
A brief description of the role goes here.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||||
|
|
||||||
|
- hosts: servers
|
||||||
|
roles:
|
||||||
|
- { role: username.rolename, x: 42 }
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
6
devops/backup/defaults/main.yml
Normal file
6
devops/backup/defaults/main.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
# defaults file for gitlab
|
||||||
|
|
||||||
|
gitlab_container_name: gitlab
|
||||||
|
gitlab_backup_directory: # Remote path to the mounted volume containing backups
|
||||||
|
gitlab_local_backup_directory: # Local path to store gitlab backups remotely
|
2
devops/backup/handlers/main.yml
Normal file
2
devops/backup/handlers/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# handlers file for gitlab
|
3
devops/backup/meta/main.yml
Normal file
3
devops/backup/meta/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies: []
|
||||||
|
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||||
|
# if you add dependencies to this list.
|
29
devops/backup/tasks/girder.yml
Normal file
29
devops/backup/tasks/girder.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
# tasks file for gitlab
|
||||||
|
- name: Ensure a gitlab container is running.
|
||||||
|
docker_container:
|
||||||
|
name: "{{ gitlab_container_name }}"
|
||||||
|
state: present
|
||||||
|
image: gitlab/gitlab-ce:14.7.0-ce.0
|
||||||
|
comparisons:
|
||||||
|
'*': ignore
|
||||||
|
|
||||||
|
- name: Start gitlab backup
|
||||||
|
community.docker.docker_container_exec:
|
||||||
|
container: "{{ gitlab_container_name }}"
|
||||||
|
command: gitlab-backup create GZIP_RSYNCABLE=yes SKIP=registry
|
||||||
|
|
||||||
|
- name: Get list of backups
|
||||||
|
find:
|
||||||
|
paths: "{{ gitlab_backup_directory }}"
|
||||||
|
register: found_files
|
||||||
|
|
||||||
|
- name: Get latest backup
|
||||||
|
set_fact:
|
||||||
|
latest_file: "{{ found_files.files | sort(attribute='mtime',reverse=true) | first }}"
|
||||||
|
|
||||||
|
- name: Download latest backup from remote
|
||||||
|
ansible.posix.synchronize:
|
||||||
|
src: "{{ latest_file.path }}"
|
||||||
|
dest: "{{ gitlab_local_backup_directory }}"
|
||||||
|
mode: pull
|
29
devops/backup/tasks/gitlab.yml
Normal file
29
devops/backup/tasks/gitlab.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
# tasks file for gitlab
|
||||||
|
- name: Ensure a gitlab container is running.
|
||||||
|
docker_container:
|
||||||
|
name: "{{ gitlab_container_name }}"
|
||||||
|
state: present
|
||||||
|
image: gitlab/gitlab-ce:14.7.0-ce.0
|
||||||
|
comparisons:
|
||||||
|
'*': ignore
|
||||||
|
|
||||||
|
- name: Start gitlab backup
|
||||||
|
community.docker.docker_container_exec:
|
||||||
|
container: "{{ gitlab_container_name }}"
|
||||||
|
command: gitlab-backup create GZIP_RSYNCABLE=yes SKIP=registry
|
||||||
|
|
||||||
|
- name: Get list of backups
|
||||||
|
find:
|
||||||
|
paths: "{{ gitlab_backup_directory }}"
|
||||||
|
register: found_files
|
||||||
|
|
||||||
|
- name: Get latest backup
|
||||||
|
set_fact:
|
||||||
|
latest_file: "{{ found_files.files | sort(attribute='mtime',reverse=true) | first }}"
|
||||||
|
|
||||||
|
- name: Download latest backup from remote
|
||||||
|
ansible.posix.synchronize:
|
||||||
|
src: "{{ latest_file.path }}"
|
||||||
|
dest: "{{ gitlab_local_backup_directory }}"
|
||||||
|
mode: pull
|
7
devops/backup/tasks/main.yml
Normal file
7
devops/backup/tasks/main.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Backup gitlab
|
||||||
|
include_tasks: gitlab.yml
|
||||||
|
when: inventory_hostname in groups['mainframe']
|
||||||
|
tags:
|
||||||
|
- gitlab
|
2
devops/backup/tests/inventory
Normal file
2
devops/backup/tests/inventory
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
5
devops/backup/tests/test.yml
Normal file
5
devops/backup/tests/test.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- gitlab
|
2
devops/backup/vars/main.yml
Normal file
2
devops/backup/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for gitlab
|
8
devops/hosts.yml
Normal file
8
devops/hosts.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[mainframe]
|
||||||
|
|
||||||
|
|
||||||
|
[girder_production]
|
||||||
|
|
||||||
|
[all:vars]
|
||||||
|
ansible_ssh_private_key_file=~/.ssh/key
|
||||||
|
ansible_python_interpreter=/usr/bin/python3
|
Loading…
Reference in New Issue
Block a user