Add gitlab role with backup task
This commit is contained in:
parent
e400549073
commit
cc46c0e89e
@ -1,3 +1,6 @@
|
|||||||
# Ansible
|
# Ansible
|
||||||
|
|
||||||
Catalogue of Ansible playbooks and helper scripts for server management
|
Catalogue of Ansible playbooks and helper scripts for server management
|
||||||
|
|
||||||
|
#### Test ansible scripts locally
|
||||||
|
ansible-playbook playbook.yml --connection=local --inventory=127.0.0.1, --limit 127.0.0.1
|
||||||
|
29
gitlab/.travis.yml
Normal file
29
gitlab/.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
gitlab/README.md
Normal file
38
gitlab/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).
|
5
gitlab/defaults/main.yml
Normal file
5
gitlab/defaults/main.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
# 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
gitlab/handlers/main.yml
Normal file
2
gitlab/handlers/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# handlers file for gitlab
|
3
gitlab/meta/main.yml
Normal file
3
gitlab/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.
|
28
gitlab/tasks/main.yml
Normal file
28
gitlab/tasks/main.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
# tasks file for gitlab
|
||||||
|
- name: Ensure a gitlab container is running.
|
||||||
|
docker_container:
|
||||||
|
name: "{{ gitlab_container_name }}"
|
||||||
|
state: present
|
||||||
|
image: gitlab/gitlab-ce
|
||||||
|
container_default_behavior: no_defaults
|
||||||
|
|
||||||
|
- name: Start gitlab backup
|
||||||
|
community.docker.docker_container_exec:
|
||||||
|
container: "{{ gitlab_container_name }}"
|
||||||
|
command: gitlab-backup create GZIP_RSYNCABLE=yes
|
||||||
|
|
||||||
|
- 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 }}"
|
||||||
|
delegate_to: delegate.host
|
2
gitlab/tests/inventory
Normal file
2
gitlab/tests/inventory
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
5
gitlab/tests/test.yml
Normal file
5
gitlab/tests/test.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- gitlab
|
2
gitlab/vars/main.yml
Normal file
2
gitlab/vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for gitlab
|
5
playbook.yml
Normal file
5
playbook.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- gitlab
|
Loading…
Reference in New Issue
Block a user