From d2e59d6bbbfc9bc62bdb8cc47dc8cd555c544ad5 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 11 Feb 2022 17:49:06 +0100 Subject: [PATCH] Add temporary devops rework --- devops/README.md | 8 +++++++ devops/backup.yml | 5 +++++ devops/backup/.travis.yml | 29 +++++++++++++++++++++++++ devops/backup/README.md | 38 +++++++++++++++++++++++++++++++++ devops/backup/defaults/main.yml | 6 ++++++ devops/backup/handlers/main.yml | 2 ++ devops/backup/meta/main.yml | 3 +++ devops/backup/tasks/girder.yml | 29 +++++++++++++++++++++++++ devops/backup/tasks/gitlab.yml | 29 +++++++++++++++++++++++++ devops/backup/tasks/main.yml | 7 ++++++ devops/backup/tests/inventory | 2 ++ devops/backup/tests/test.yml | 5 +++++ devops/backup/vars/main.yml | 2 ++ devops/hosts.yml | 8 +++++++ 14 files changed, 173 insertions(+) create mode 100644 devops/README.md create mode 100644 devops/backup.yml create mode 100644 devops/backup/.travis.yml create mode 100644 devops/backup/README.md create mode 100644 devops/backup/defaults/main.yml create mode 100644 devops/backup/handlers/main.yml create mode 100644 devops/backup/meta/main.yml create mode 100644 devops/backup/tasks/girder.yml create mode 100644 devops/backup/tasks/gitlab.yml create mode 100644 devops/backup/tasks/main.yml create mode 100644 devops/backup/tests/inventory create mode 100644 devops/backup/tests/test.yml create mode 100644 devops/backup/vars/main.yml create mode 100644 devops/hosts.yml diff --git a/devops/README.md b/devops/README.md new file mode 100644 index 0000000..c2c73bf --- /dev/null +++ b/devops/README.md @@ -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 diff --git a/devops/backup.yml b/devops/backup.yml new file mode 100644 index 0000000..e2153f1 --- /dev/null +++ b/devops/backup.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + + roles: + - backup diff --git a/devops/backup/.travis.yml b/devops/backup/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/devops/backup/.travis.yml @@ -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/ \ No newline at end of file diff --git a/devops/backup/README.md b/devops/backup/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/devops/backup/README.md @@ -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). diff --git a/devops/backup/defaults/main.yml b/devops/backup/defaults/main.yml new file mode 100644 index 0000000..a2216a5 --- /dev/null +++ b/devops/backup/defaults/main.yml @@ -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 diff --git a/devops/backup/handlers/main.yml b/devops/backup/handlers/main.yml new file mode 100644 index 0000000..fbd0ddd --- /dev/null +++ b/devops/backup/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for gitlab diff --git a/devops/backup/meta/main.yml b/devops/backup/meta/main.yml new file mode 100644 index 0000000..f27bd5c --- /dev/null +++ b/devops/backup/meta/main.yml @@ -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. diff --git a/devops/backup/tasks/girder.yml b/devops/backup/tasks/girder.yml new file mode 100644 index 0000000..187a38f --- /dev/null +++ b/devops/backup/tasks/girder.yml @@ -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 diff --git a/devops/backup/tasks/gitlab.yml b/devops/backup/tasks/gitlab.yml new file mode 100644 index 0000000..187a38f --- /dev/null +++ b/devops/backup/tasks/gitlab.yml @@ -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 diff --git a/devops/backup/tasks/main.yml b/devops/backup/tasks/main.yml new file mode 100644 index 0000000..f9372b3 --- /dev/null +++ b/devops/backup/tasks/main.yml @@ -0,0 +1,7 @@ +--- + +- name: Backup gitlab + include_tasks: gitlab.yml + when: inventory_hostname in groups['mainframe'] + tags: + - gitlab diff --git a/devops/backup/tests/inventory b/devops/backup/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/devops/backup/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/devops/backup/tests/test.yml b/devops/backup/tests/test.yml new file mode 100644 index 0000000..11cf798 --- /dev/null +++ b/devops/backup/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - gitlab diff --git a/devops/backup/vars/main.yml b/devops/backup/vars/main.yml new file mode 100644 index 0000000..94bd35b --- /dev/null +++ b/devops/backup/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for gitlab diff --git a/devops/hosts.yml b/devops/hosts.yml new file mode 100644 index 0000000..5fb00b3 --- /dev/null +++ b/devops/hosts.yml @@ -0,0 +1,8 @@ +[mainframe] + + +[girder_production] + +[all:vars] +ansible_ssh_private_key_file=~/.ssh/key +ansible_python_interpreter=/usr/bin/python3