diff --git a/README.md b/README.md index f09b818..c26ef76 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # Ansible -Catalogue of Ansible playbooks and helper scripts for server management \ No newline at end of file +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 diff --git a/gitlab/.travis.yml b/gitlab/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/gitlab/.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/gitlab/README.md b/gitlab/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/gitlab/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/gitlab/defaults/main.yml b/gitlab/defaults/main.yml new file mode 100644 index 0000000..0f20e03 --- /dev/null +++ b/gitlab/defaults/main.yml @@ -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 diff --git a/gitlab/handlers/main.yml b/gitlab/handlers/main.yml new file mode 100644 index 0000000..fbd0ddd --- /dev/null +++ b/gitlab/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for gitlab diff --git a/gitlab/meta/main.yml b/gitlab/meta/main.yml new file mode 100644 index 0000000..f27bd5c --- /dev/null +++ b/gitlab/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/gitlab/tasks/main.yml b/gitlab/tasks/main.yml new file mode 100644 index 0000000..244937a --- /dev/null +++ b/gitlab/tasks/main.yml @@ -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 diff --git a/gitlab/tests/inventory b/gitlab/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/gitlab/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/gitlab/tests/test.yml b/gitlab/tests/test.yml new file mode 100644 index 0000000..11cf798 --- /dev/null +++ b/gitlab/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - gitlab diff --git a/gitlab/vars/main.yml b/gitlab/vars/main.yml new file mode 100644 index 0000000..94bd35b --- /dev/null +++ b/gitlab/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for gitlab diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..1301852 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + + roles: + - gitlab