From f24607234cf81cefbad167d7fa6a9afd7fe43149 Mon Sep 17 00:00:00 2001 From: Gaudenz Steinlin Date: Mon, 19 Dec 2022 16:25:16 +0100 Subject: [PATCH] Remove warn argument from command and shell module The `warn` argument to the command and shell modules was deprecated in Ansible 2.11 and removed in 2.14. This argument is no longer needed as no warnings are issued anymore if these modules are used in ways which could be replaced by an Ansible module. See https://github.com/ansible/ansible/pull/70504. (cherry-picked from commit a2a65551b833342cb170d2fa719eb0ae13a30761) --- .../roles/gitlab/tasks/configure_gitaly.yml | 125 ++++++++++++++++++ .../gitlab/tasks/configure_gitlab-pages.yml | 118 +++++++++++++++++ .../gitlab/tasks/configure_gitlab-shell.yml | 122 +++++++++++++++++ .../tasks/configure_gitlab-workhorse.yml | 103 +++++++++++++++ .../roles/gitlab/tasks/download_gitlab_ce.yml | 77 +++++++++++ 5 files changed, 545 insertions(+) create mode 100644 ansible/roles/gitlab/tasks/configure_gitaly.yml create mode 100644 ansible/roles/gitlab/tasks/configure_gitlab-pages.yml create mode 100644 ansible/roles/gitlab/tasks/configure_gitlab-shell.yml create mode 100644 ansible/roles/gitlab/tasks/configure_gitlab-workhorse.yml create mode 100644 ansible/roles/gitlab/tasks/download_gitlab_ce.yml diff --git a/ansible/roles/gitlab/tasks/configure_gitaly.yml b/ansible/roles/gitlab/tasks/configure_gitaly.yml new file mode 100644 index 0000000000..8b10a00835 --- /dev/null +++ b/ansible/roles/gitlab/tasks/configure_gitaly.yml @@ -0,0 +1,125 @@ +--- +# Copyright (C) 2015-2017 Maciej Delmanowski +# Copyright (C) 2015-2017 DebOps +# SPDX-License-Identifier: GPL-3.0-only + +# gitaly is checked out based on tags instead of branches, and since we +# cannot work with tags from a bare repository, we need to work around it +# a little. + +- name: Check if bare repository is cloned + stat: + path: '{{ gitlab__gitaly_dest }}' + register: gitlab_register_gitaly_cloned + +- name: Save current checkout hash for update + command: git rev-parse HEAD + args: + chdir: '{{ gitlab__gitaly_dest }}' + register: gitlab_register_gitaly_current_head + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitaly_cloned.stat.exists + +- name: Change current HEAD to master in bare repository for update + command: git symbolic-ref HEAD refs/heads/master + args: + chdir: '{{ gitlab__gitaly_dest }}' + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitaly_cloned.stat.exists + +- name: Clone gitaly source code + git: + repo: '{{ gitlab__gitaly_repo }}' + dest: '{{ gitlab__gitaly_dest }}' + version: 'master' + bare: True + update: True + become: True + become_user: '{{ gitlab_user }}' + +- name: Restore HEAD to previous checkout + copy: + content: '{{ gitlab_register_gitaly_current_head.stdout }}' + dest: '{{ gitlab__gitaly_dest + "/HEAD" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + changed_when: False + when: gitlab_register_gitaly_cloned.stat.exists + +- name: Create gitaly checkout directory + file: + path: '{{ gitlab__gitaly_checkout }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0755' + +- name: Prepare gitaly worktree + copy: + content: 'gitdir: {{ gitlab__gitaly_dest }}' + dest: '{{ gitlab__gitaly_checkout + "/.git" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + +- name: Get currently checked out git tag + command: git describe --tags + environment: + GIT_WORK_TREE: '{{ gitlab__gitaly_checkout }}' + args: + chdir: '{{ gitlab__gitaly_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_gitaly_target_tag + changed_when: gitlab_register_gitaly_target_tag.stdout != gitlab__fact_version.gitaly + +- name: Checkout gitaly + command: git checkout -f {{ gitlab__fact_version.gitaly }} + environment: + GIT_WORK_TREE: '{{ gitlab__gitaly_checkout }}' + args: + chdir: '{{ gitlab__gitaly_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_gitlab__gitaly_checkout + when: (gitlab__fact_version.gitaly != gitlab_register_gitaly_target_tag.stdout) or + not gitlab_register_gitaly_cloned.stat.exists + +- name: Stop gitaly service for an upgrade + service: # noqa no-handler + name: 'gitlab-gitaly.service' + state: 'stopped' + when: (ansible_local|d() and ansible_local.gitlab|d() and + (ansible_local.gitlab.installed|d() | bool) and + ansible_service_mgr == 'systemd' and + gitlab_register_gitlab__gitaly_checkout is changed) + +- name: Setup gitaly + make: # noqa no-handler + chdir: '{{ gitlab__gitaly_checkout }}' + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitlab__gitaly_checkout is changed + +- name: Start gitaly service after an upgrade + service: # noqa no-handler + name: 'gitlab-gitaly.service' + state: 'started' + when: (ansible_local|d() and ansible_local.gitlab|d() and + (ansible_local.gitlab.installed|d() | bool) and + ansible_service_mgr == 'systemd' and + gitlab_register_gitlab__gitaly_checkout is changed) + +- name: Configure Gitaly + template: + src: 'var/local/git/gitaly/config.toml.j2' + dest: '{{ gitlab__gitaly_checkout + "/config.toml" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + notify: 'Restart gitaly' diff --git a/ansible/roles/gitlab/tasks/configure_gitlab-pages.yml b/ansible/roles/gitlab/tasks/configure_gitlab-pages.yml new file mode 100644 index 0000000000..990d53bbf1 --- /dev/null +++ b/ansible/roles/gitlab/tasks/configure_gitlab-pages.yml @@ -0,0 +1,118 @@ +--- +# Copyright (C) 2015-2017 Maciej Delmanowski +# Copyright (C) 2015-2017 DebOps +# SPDX-License-Identifier: GPL-3.0-only + +# gitlab-pages checked out based on tags instead of branches, and since we +# cannot work with tags from a bare repository, we need to work around it +# a little. + +- name: Check if bare repository is cloned + stat: + path: '{{ gitlab_pages_dest }}' + register: gitlab_register_pages_cloned + +- name: Save current checkout hash for update + command: git rev-parse HEAD + args: + chdir: '{{ gitlab_pages_dest }}' + register: gitlab_register_pages_current_head + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_pages_cloned.stat|d() and + gitlab_register_pages_cloned.stat.exists + +- name: Change current HEAD to master in bare repository for update + command: git symbolic-ref HEAD refs/heads/master + args: + chdir: '{{ gitlab_pages_dest }}' + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_pages_cloned.stat|d() and + gitlab_register_pages_cloned.stat.exists + +- name: Clone gitlab-pages source code + git: + repo: '{{ gitlab_pages_repo }}' + dest: '{{ gitlab_pages_dest }}' + version: 'master' + bare: True + update: True + become: True + become_user: '{{ gitlab_user }}' + +- name: Restore HEAD to previous checkout + copy: + content: '{{ gitlab_register_pages_current_head.stdout }}' + dest: '{{ gitlab_pages_dest + "/HEAD" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + changed_when: False + when: gitlab_register_pages_cloned.stat|d() and + gitlab_register_pages_cloned.stat.exists + +- name: Check if gitlab-pages is checked out + stat: + path: '{{ gitlab_pages_checkout }}' + register: gitlab_register_pages_directory + +- name: Create gitlab-pages checkout directory + file: + path: '{{ gitlab_pages_checkout }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0755' + +- name: Prepare gitlab-pages worktree + copy: + content: 'gitdir: {{ gitlab_pages_dest }}' + dest: '{{ gitlab_pages_checkout + "/.git" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + +- name: Get currently checked out git tag + command: git describe --tags + environment: + GIT_WORK_TREE: '{{ gitlab_pages_checkout }}' + args: + chdir: '{{ gitlab_pages_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_pages_target_tag + changed_when: gitlab_register_pages_target_tag.stdout != gitlab__fact_version.pages + +- name: Checkout gitlab-pages + command: git checkout -f {{ gitlab__fact_version.pages }} + environment: + GIT_WORK_TREE: '{{ gitlab_pages_checkout }}' + args: + chdir: '{{ gitlab_pages_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_pages_checkout + when: (gitlab__fact_version.pages|d() != gitlab_register_pages_target_tag.stdout|d()) or + (gitlab_register_pages_cloned.stat|d() and not gitlab_register_pages_cloned.stat.exists) + +- name: Setup gitlab-pages + make: # noqa no-handler + chdir: '{{ gitlab_pages_checkout }}' + environment: + GOPATH: '{{ gitlab_app_root_path }}/go' + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_pages_checkout is changed + +- name: Setup GitLab Pages default variables + template: + src: 'etc/default/gitlab-pages.j2' + dest: '/etc/default/gitlab-pages' + owner: 'root' + group: '{{ gitlab_group }}' + mode: '0640' + when: gitlab_version is version_compare("12.8", operator="ge", strict=True) + notify: [ 'Restart gitlab', 'Restart gitlab.slice' ] diff --git a/ansible/roles/gitlab/tasks/configure_gitlab-shell.yml b/ansible/roles/gitlab/tasks/configure_gitlab-shell.yml new file mode 100644 index 0000000000..345cb0ed48 --- /dev/null +++ b/ansible/roles/gitlab/tasks/configure_gitlab-shell.yml @@ -0,0 +1,122 @@ +--- +# Copyright (C) 2015-2017 Maciej Delmanowski +# Copyright (C) 2015-2017 DebOps +# SPDX-License-Identifier: GPL-3.0-only + +# gitlab-shell is checked out based on tags instead of branches, and since we +# cannot work with tags from a bare repository, we need to work around it +# a little. + +- name: Check if bare repository is cloned + stat: + path: '{{ gitlab_shell_git_dest }}' + register: gitlab_register_shell_cloned + +- name: Save current checkout hash for update + command: git rev-parse HEAD + args: + chdir: '{{ gitlab_shell_git_dest }}' + register: gitlab_register_shell_current_head + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_shell_cloned.stat.exists + +- name: Change current HEAD to master in bare repository for update + command: git symbolic-ref HEAD refs/heads/master + args: + chdir: '{{ gitlab_shell_git_dest }}' + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_shell_cloned.stat.exists + +- name: Create GitLab source directory + file: + path: '{{ gitlab_src_path }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0750' + +- name: Clone gitlab-shell source code + git: + repo: '{{ gitlab_shell_git_repo }}' + dest: '{{ gitlab_shell_git_dest }}' + version: 'master' + bare: True + update: True + become: True + become_user: '{{ gitlab_user }}' + +- name: Restore HEAD to previous checkout + copy: + content: '{{ gitlab_register_shell_current_head.stdout }}' + dest: '{{ gitlab_shell_git_dest + "/HEAD" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + changed_when: False + when: gitlab_register_shell_cloned.stat.exists + +- name: Create gitlab-shell checkout directory + file: + path: '{{ gitlab_shell_git_checkout }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0755' + +- name: Prepare gitlab-shell worktree + copy: + content: 'gitdir: {{ gitlab_shell_git_dest }}' + dest: '{{ gitlab_shell_git_checkout + "/.git" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + +- name: Get currently checked out git tag + command: git describe --tags + environment: + GIT_WORK_TREE: '{{ gitlab_shell_git_checkout }}' + args: + chdir: '{{ gitlab_shell_git_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_shell_target_tag + changed_when: gitlab_register_shell_target_tag.stdout != gitlab__fact_version.shell + +- name: Checkout gitlab-shell + command: git checkout --force {{ gitlab__fact_version.shell }} + environment: + GIT_WORK_TREE: '{{ gitlab_shell_git_checkout }}' + args: + chdir: '{{ gitlab_shell_git_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_shell_checkout + when: ((gitlab__fact_version.shell != gitlab_register_shell_target_tag.stdout) or + not gitlab_register_shell_cloned.stat.exists | bool) + +- name: Configure gitlab-shell + template: + src: 'var/local/git/gitlab-shell/config.yml.j2' + dest: '{{ gitlab_shell_git_checkout + "/config.yml" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0640' + +- name: Create GitLab data root directories + file: + path: '{{ item }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0750' + with_items: [ '{{ gitlab_repositories_path }}', '{{ gitlab_satellites_path }}' ] + +- name: Setup gitlab-shell + shell: ./bin/install ; make compile + args: # noqa no-handler + chdir: '{{ gitlab_shell_git_checkout }}' + when: gitlab_register_shell_checkout is changed diff --git a/ansible/roles/gitlab/tasks/configure_gitlab-workhorse.yml b/ansible/roles/gitlab/tasks/configure_gitlab-workhorse.yml new file mode 100644 index 0000000000..6f457052a8 --- /dev/null +++ b/ansible/roles/gitlab/tasks/configure_gitlab-workhorse.yml @@ -0,0 +1,103 @@ +--- +# Copyright (C) 2015-2017 Maciej Delmanowski +# Copyright (C) 2015-2017 DebOps +# SPDX-License-Identifier: GPL-3.0-only + +# gitlab-workhorse is checked out based on tags instead of branches, and since we +# cannot work with tags from a bare repository, we need to work around it +# a little. + +- name: Check if bare repository is cloned + stat: + path: '{{ gitlab_workhorse_dest }}' + register: gitlab_register_gitlab_workhorse_cloned + +- name: Save current checkout hash for update + command: git rev-parse HEAD + args: + chdir: '{{ gitlab_workhorse_dest }}' + register: gitlab_register_gitlab_workhorse_current_head + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitlab_workhorse_cloned.stat.exists + +- name: Change current HEAD to master in bare repository for update + command: git symbolic-ref HEAD refs/heads/master + args: + chdir: '{{ gitlab_workhorse_dest }}' + changed_when: False + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitlab_workhorse_cloned.stat.exists + +- name: Clone gitlab-workhorse source code + git: + repo: '{{ gitlab_workhorse_repo }}' + dest: '{{ gitlab_workhorse_dest }}' + version: 'master' + bare: True + update: True + become: True + become_user: '{{ gitlab_user }}' + +- name: Restore HEAD to previous checkout + copy: + content: '{{ gitlab_register_gitlab_workhorse_current_head.stdout }}' + dest: '{{ gitlab_workhorse_dest + "/HEAD" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + changed_when: False + when: gitlab_register_gitlab_workhorse_cloned.stat.exists + +- name: Check if gitlab-workhorse is checked out + stat: + path: '{{ gitlab_workhorse_checkout }}' + register: gitlab_register_gitlab_workhorse_directory + +- name: Create gitlab-workhorse checkout directory + file: + path: '{{ gitlab_workhorse_checkout }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0755' + +- name: Prepare gitlab-workhorse worktree + copy: + content: 'gitdir: {{ gitlab_workhorse_dest }}' + dest: '{{ gitlab_workhorse_checkout + "/.git" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + +- name: Get currently checked out git tag + command: git describe --tags + environment: + GIT_WORK_TREE: '{{ gitlab_workhorse_checkout }}' + args: + chdir: '{{ gitlab_workhorse_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_gitlab_workhorse_target_tag + changed_when: gitlab_register_gitlab_workhorse_target_tag.stdout != gitlab__fact_version.workhorse + +- name: Checkout gitlab-workhorse + command: git checkout -f {{ gitlab__fact_version.workhorse }} + environment: + GIT_WORK_TREE: '{{ gitlab_workhorse_checkout }}' + args: + chdir: '{{ gitlab_workhorse_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_gitlab_workhorse_checkout + when: (gitlab__fact_version.workhorse != gitlab_register_gitlab_workhorse_target_tag.stdout) or + not gitlab_register_gitlab_workhorse_cloned.stat.exists + +- name: Setup gitlab-workhorse + make: # noqa no-handler + chdir: '{{ gitlab_workhorse_checkout }}' + become: True + become_user: '{{ gitlab_user }}' + when: gitlab_register_gitlab_workhorse_checkout is changed diff --git a/ansible/roles/gitlab/tasks/download_gitlab_ce.yml b/ansible/roles/gitlab/tasks/download_gitlab_ce.yml new file mode 100644 index 0000000000..f94c9a845a --- /dev/null +++ b/ansible/roles/gitlab/tasks/download_gitlab_ce.yml @@ -0,0 +1,77 @@ +--- +# Copyright (C) 2015-2017 Maciej Delmanowski +# Copyright (C) 2015-2017 DebOps +# SPDX-License-Identifier: GPL-3.0-only + +# ---- git clone && git checkout ---- + +- name: Create GitLab source directory + file: + path: '{{ gitlab_src_path }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0750' + +- name: Clone GitLab CE source code + git: + repo: '{{ gitlab_ce_git_repo }}' + dest: '{{ gitlab_ce_git_dest }}' + version: 'master' + bare: True + update: True + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_ce_source + +- name: Check if GitLab CE is checked out + stat: + path: '{{ gitlab_ce_git_checkout }}' + register: gitlab_register_ce_directory + +- name: Create GitLab CE checkout directory + file: + path: '{{ gitlab_ce_git_checkout }}' + state: 'directory' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0755' + +- name: Prepare GitLab CE worktree + copy: + content: 'gitdir: {{ gitlab_ce_git_dest }}' + dest: '{{ gitlab_ce_git_checkout + "/.git" }}' + owner: '{{ gitlab_user }}' + group: '{{ gitlab_group }}' + mode: '0644' + +- name: Get commit hash of target checkout + command: git rev-parse {{ gitlab__release }} + environment: + GIT_WORK_TREE: '{{ gitlab_ce_git_checkout }}' + args: + chdir: '{{ gitlab_ce_git_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_ce_target_branch + changed_when: gitlab_register_ce_target_branch.stdout != gitlab_register_ce_source.before + +- include: gitlab_ce_pre_upgrade.yml + when: (ansible_local|d() and ansible_local.gitlab|d() and + (ansible_local.gitlab.installed|d() | bool) and + ((gitlab_register_ce_target_branch.stdout != gitlab_register_ce_source.before) or + (ansible_local.gitlab.version is defined and ansible_local.gitlab.version != gitlab_version))) + +- name: Checkout GitLab CE + command: git checkout -f {{ gitlab__release }} + environment: + GIT_WORK_TREE: '{{ gitlab_ce_git_checkout }}' + args: + chdir: '{{ gitlab_ce_git_dest }}' + become: True + become_user: '{{ gitlab_user }}' + register: gitlab_register_ce_checkout + when: (gitlab_register_ce_source.before is undefined or + (gitlab_register_ce_source.before is defined and + gitlab_register_ce_target_branch.stdout is defined and + gitlab_register_ce_source.before != gitlab_register_ce_target_branch.stdout))