├── git-updater ├── meta │ └── main.yml ├── templates │ ├── cleanup.sh.j2 │ └── update.sh.j2 ├── README.md └── tasks │ └── main.yml ├── LICENSE └── README.md /git-updater/meta/main.yml: -------------------------------------------------------------------------------- 1 | galaxy_info: 2 | author: The Wikidata Team 3 | description: cronjob that repeatedly pulls the latest version of the master branch of git remote(s) 4 | company: -------------------------------------------------------------------------------- /git-updater/templates/cleanup.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | GIT_PATH=$1 3 | LOG_DIR=$2 4 | CLEANUP_LOG=$LOG_DIR/cleanup.log 5 | ERROR_LOG=$LOG_DIR/error.log 6 | 7 | log () { 8 | echo "$1" | tee -a "$2" 9 | } 10 | 11 | log "########### cleanup start $(date) $GIT_PATH ###########" "$CLEANUP_LOG" 12 | 13 | cd ${GIT_PATH} 14 | git gc && git repack -Ad && git prune >> "$ERROR_LOG" | tee -a ${CLEANUP_LOG} 15 | 16 | log "########### cleanup end $(date) $GIT_PATH ###########" "$CLEANUP_LOG" 17 | -------------------------------------------------------------------------------- /git-updater/templates/update.sh.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | GIT_PATH=$1 3 | LOG_DIR=$2 4 | UPDATE_LOG=$LOG_DIR/update.log 5 | GIT_LOG=$LOG_DIR/git.log 6 | COMPOSER_LOG=$LOG_DIR/composer.log 7 | MAINT_LOG=$LOG_DIR/maintenance.log 8 | ERROR_LOG=$LOG_DIR/error.log 9 | 10 | log () { 11 | echo "$1" | tee -a "$2" 12 | } 13 | 14 | log_all () { 15 | echo "$1" | tee -a "${UPDATE_LOG}" "${GIT_LOG}" "${COMPOSER_LOG}" "${MAINT_LOG}" "${ERROR_LOG}" 16 | } 17 | 18 | # start 19 | log_all "########### $(date) ###########" 20 | 21 | log "## updating ${GIT_PATH}" "${UPDATE_LOG} ${GIT_LOG}" 22 | cd ${GIT_PATH} 23 | git pull origin master 2>> "$ERROR_LOG" | tee -a ${GIT_LOG} 24 | git submodule update 2>> "$ERROR_LOG" | tee -a ${GIT_LOG} 25 | 26 | # done 27 | log_all "########### $(date) ###########" 28 | -------------------------------------------------------------------------------- /git-updater/README.md: -------------------------------------------------------------------------------- 1 | Role Name 2 | ========= 3 | 4 | This role install a cronjob that repeatedly pulls the latest version of the master branch of git remote(s). 5 | 6 | Role Variables 7 | -------------- 8 | 9 | USERNAME: the user that should be running the update cronjob 10 | SCRIPTS_DIR: where the update cronjob script should be saved 11 | LOG_DIR: directory where logs from updating should go 12 | git_repositories: which repositories should be updated. 13 | 14 | Example Playbook 15 | ---------------- 16 | 17 | - hosts: test_systems 18 | name: "Setup and run a test system for the 'WikibaseManifest' extension" 19 | become: yes 20 | roles: 21 | - role: '/home/tom/src/wikimedia/wmde-ansible-roles/git-updater' 22 | vars: 23 | git_directories: 24 | - "/opt/Wikibase/src" 25 | 26 | License 27 | ------- 28 | 29 | BSD 30 | 31 | Author Information 32 | ------------------ 33 | 34 | The Wikidata Team 35 | -------------------------------------------------------------------------------- /git-updater/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Create scripts directory 3 | file: 4 | path: "{{ SCRIPTS_DIR }}" 5 | owner: "{{ USERNAME }}" 6 | group: "{{ USERNAME }}" 7 | state: directory 8 | - name: Ensure git_update scripts are in place 9 | template: 10 | dest: "{{ SCRIPTS_DIR }}/git_updater.sh" 11 | src: "templates/update.sh.j2" 12 | owner: "{{ USERNAME }}" 13 | group: "{{ USERNAME }}" 14 | mode: 0774 15 | - name: Ensure update script runs every five minutes, from 6am to 9pm 16 | cron: 17 | name: "git_updater: {{item}}" 18 | minute: "*/5" 19 | hour: "6-21" 20 | job: "{{ SCRIPTS_DIR }}/git_updater.sh {{ item }} {{ LOG_DIR }}" 21 | user: "{{ USERNAME }}" 22 | loop: "{{ git_directories }}" 23 | - name: Ensure cleanup scripts are in place 24 | template: 25 | dest: "{{ SCRIPTS_DIR }}/cleanup.sh" 26 | src: "templates/cleanup.sh.j2" 27 | owner: "{{ USERNAME }}" 28 | group: "{{ USERNAME }}" 29 | mode: 0774 30 | - name: Ensure diskspace is cleaned once a day at 10pm 31 | cron: 32 | name: "git_updater: {{item}}" 33 | hour: "22" 34 | job: "{{ SCRIPTS_DIR }}/cleanup.sh {{ item }} {{ LOG_DIR }}" 35 | user: "{{ USERNAME }}" 36 | loop: "{{ git_directories }}" 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Wikimedia Deutschland e. V. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Roles 2 | 3 | Repo for storing ansible components and grouping them in roles to be reused in different projects. 4 | 5 | More about ansible roles can be found at [Ansible's Docs](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html). 6 | 7 | ## Example 8 | 9 | The following snippets show how to use the `git_updater` ansible role in a project. 10 | ```yaml 11 | // requirements.yml 12 | 13 | --- 14 | roles: 15 | - src: git+https://github.com/wmde/ansible-roles.git 16 | version: main 17 | name: git_updater 18 | ``` 19 | 20 | ```yaml 21 | // setup.yml 22 | 23 | - hosts: test_systems 24 | name: "Setup and run a test system for the 'WikibaseManifest' extension" 25 | become: yes 26 | vars: 27 | VECTOR_SUBPATH: "skins/Vector" 28 | ULS_SUBPATH: "extensions/UniversalLanguageSelector" 29 | CLDR_SUBPATH: "extensions/cldr" 30 | WIKIBASE_SUBPATH: "extensions/Wikibase" 31 | WIKIBASEMANIFEST_SUBPATH: "extensions/WikibaseManifest" 32 | OAUTH_SUBPATH: "extensions/OAuth" 33 | roles: 34 | - role: git_updater 35 | vars: 36 | git_directories: 37 | - "{{ MW_PATH }}" 38 | - "{{ MW_PATH }}/{{ VECTOR_SUBPATH }}" 39 | - "{{ MW_PATH }}/{{ ULS_SUBPATH }}" 40 | - "{{ MW_PATH }}/{{ CLDR_SUBPATH }}" 41 | - "{{ MW_PATH }}/{{ WIKIBASE_SUBPATH }}" 42 | - "{{ MW_PATH }}/{{ WIKIBASEMANIFEST_SUBPATH }}" 43 | - "{{ MW_PATH }}/{{ OAUTH_SUBPATH }}" 44 | USERNAME: mediawiki 45 | 46 | ``` 47 | 48 | :warning: You need to use ansible-galaxy to work with ansible roles. 49 | 50 | ```sh 51 | $ ansible-galaxy install -r requirements.yml 52 | $ ansible-playbook setup.yml --limit .wikidata-dev.eqiad.wmflabs 53 | ``` 54 | 55 | ### Example usage in WikibaseManifest 56 | See: [WikibaseManifest Infrastructure Code](https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/WikibaseManifest/+/refs/heads/master/infrastructure/) for somewhere this is used for WMDE test infrastructure. 57 | --------------------------------------------------------------------------------