Thank you for reading this post, don't forget to subscribe!
данная роль установит gitlab gitlab-registry gitlab-multi-runner docker
создаём структуру директорий:
mkdir -p /etc/ansible/{playbooks/roles_play,roles/gitlab-gitlab-runner/{handlers,tasks,templates}}
cat /etc/ansible/playbooks/roles_play/gitlab-ce.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
- name: Task to install gitlab, gitlab-runner, gitlab-registry hosts: 192.168.1.170 become: true ignore_errors: yes become_method: sudo gather_facts: yes vars: - gitlabrunner: true - proxy: false - proxyIP: "9.9.9.9:3128" - docker_package_state: latest - docker_install_compose: True - docker_compose_version: "1.22.0" - docker_compose_path: /usr/local/bin/docker-compose roles: - gitlab-gitlab-runner # remote_user: root # tasks: # - include: tasks/main.yml # handlers: # - include: handlers/main.yml |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/handlers/main.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
--- # handlers file for gitlab-centos - name: start_gitlab shell: gitlab-ctl start - name: yum_clean shell: yum clean all - name: Reload systemd command: systemctl daemon-reload - name: Reload docker service: name=docker state=reloaded - name: Restart docker service: name=docker state=restarted enabled=yes |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/templates/config.json
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "proxies": { "default": { "httpProxy": "http://"{{ proxyIP }}"", "httpsProxy": "https://"{{ proxyIP }}"", "noProxy": "{{groups['NOproxy'] | to_yaml}}" } } } |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/templates/http-proxy.conf
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 |
[Service] Environment="HTTP_PROXY=http://"{{ proxyIP }}"" Environment="HTTPS_PROXY=https://"{{ proxyIP }}"" Environment="NO_PROXY={{groups['NOproxy'] | to_yaml}} " |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/templates/gitlab.repo.j2
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[GitLab-Repo] name=GitLab-Repo baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/{{ ansible_distribution_major_version }}/$basearch enabled=1 #sslverify=1 #sslcacert=/etc/pki/tls/certs/ca-bundle.crt gpgkey=https://packages.gitlab.com/gpg.key repo_gpgcheck=0 metadata_expire=300 [GitLab-Repo-source] name=GitLab-Repo-source baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/{{ ansible_distribution_major_version }}/SRPMS enabled=1 #sslverify=1 #sslcacert=/etc/pki/tls/certs/ca-bundle.crt gpgkey=https://packages.gitlab.com/gpg.key repo_gpgcheck=0 metadata_expire=300 |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/templates/runner-gitlab-runner.repo
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[runner_gitlab-ci-multi-runner] name=runner_gitlab-ci-multi-runner baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/{{ ansible_distribution_major_version }}/$basearch repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 [runner_gitlab-ci-multi-runner-source] name=runner_gitlab-ci-multi-runner-source baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/{{ ansible_distribution_major_version }}/SRPMS repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/add-repo-docker.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 |
- name: Add Docker repo get_url: url: https://download.docker.com/linux/centos/docker-ce.repo dest: /etc/yum.repos.d/docer-ce.repo become: yes |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/docker-compose-preinstall.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
--- - name: purge docker-compose package yum: name: docker-compose state: removed - name: install pip yum: name: python-pip - name: install the package, force upgrade pip: name: pip executable: pip state: latest |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/docker-preinstall.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 |
- name: default packages for docker yum: name: "{{item}}" state: present with_items: - yum-utils - device-mapper-persistent-data - lvm2 - python-devel |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/docker_proxy.yaml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
--- - name: create dir for .docker and service.d file: path: "{{item}}" state: directory mode: 0755 with_items: - /root/.docker/ - /etc/systemd/system/docker.service.d/ when: proxy - name: copy template for proxy to /root/.docker/config.json template: src: /etc/ansible/roles/docker_docker_compose/templates/config.json dest: /root/.docker/config.json mode: 644 when: proxy - name: copy template for proxy to /etc/systemd/system/docker.service.d/http-proxy.conf template: src: /etc/ansible/roles/docker_docker_compose/templates/http-proxy.conf dest: /etc/systemd/system/docker.service.d/http-proxy.conf mode: 644 notify: - Reload systemd - Reload docker when: proxy |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/gitlab-gitlab-runner-preinstall.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
- name: Install pre-reqs become: yes yum: name: "{{ item }}" state: present with_items: - curl - wget - policycoreutils - pygpgme - yum-utils tags: - pre-reqs - name: Copy GitLab Repo to remote host template: src=/etc/ansible/roles/gitlab-gitlab-runner/templates/gitlab.repo.j2 dest=/etc/yum.repos.d/gitlab.repo mode='440' - name: Copy GitLab-Runner Repo to remote host template: src=/etc/ansible/roles/gitlab-gitlab-runner/templates/runner-gitlab-runner.repo dest=/etc/yum.repos.d/runner-gitlab-runner.repo mode='440' |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/gitlab-install.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
- name: Installing GitLab become: yes yum: name: gitlab-ce state: present disable_gpg_check: yes tags: - gitlab - name: Display Password debug: msg: "Login credentials for the GitLab admin are root / 5iveL!fe" tags: - gitlab |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/gitlab-registry.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
- name: Add registry to /etc/gitlab/gitlab.rb blockinfile: path: /etc/gitlab/gitlab.rb block: | external_url 'http://{{ ansible_default_ipv4.address }}' registry_external_url 'http://{{ ansible_default_ipv4.address }}:4567' registry['enable'] = true letsencrypt['enable'] = false prometheus_monitoring['enable'] = false - name: GitLab reconfigure after adding REGISTRY become: yes shell: /bin/gitlab-ctl reconfigure tags: - gitlab notify: start_gitlab |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/gitlab-runner-install.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
- name: Installing GitLab-Muli-Runner become: yes yum: name: gitlab-ci-multi-runner state: present disable_gpg_check: yes tags: - gitlab-ci-multi-runner - name: Creates directory /var/opt/gitlab-runner file: path: /var/opt/gitlab-runner state: directory mode: 755 - name: ADD user gitlab-runner user: name: gitlab-runner group: gitlab-runner - name: gitlab-multiranner start become: yes shell: gitlab-ci-multi-runner start tags: - gitlab-ci-multi-runner |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/install-docker-compose.yml
[codesyntax lang="bash" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
- name: Check current docker-compose version. command: docker-compose --version register: docker_compose_current_version changed_when: false failed_when: false - name: Delete existing docker-compose version if it's different. file: path: "{{ docker_compose_path }}" state: absent when: > docker_compose_current_version.stdout is defined and docker_compose_version not in docker_compose_current_version.stdout - name: Install Docker Compose (if configured). get_url: url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64 dest: "{{ docker_compose_path }}" mode: 0755 - name: install docker-compose stuff with pip pip: name: " {{ item }}" with_items: - pyyaml - docker-py |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/install-docker.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 |
- name: Install Docker package: name: docker-ce state: latest become: yes notify: - Restart docker |
[/codesyntax]
cat /etc/ansible/roles/gitlab-gitlab-runner/tasks/main.yml
[codesyntax lang="php" blockstate="collapsed"]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
--- - import_tasks: gitlab-gitlab-runner-preinstall.yml tags: Preinstall for gitlab and gitlab runner - import_tasks: gitlab-install.yml tags: Install gitlab - import_tasks: add-repo-docker.yml tags: Add repo docker when: gitlabrunner - import_tasks: docker-preinstall.yml tags: install packpage fo docker when: gitlabrunner - import_tasks: install-docker.yml tags: install docker when: gitlabrunner - import_tasks: docker-compose-preinstall.yml tags: install packpage fo docker-compose when: gitlabrunner - import_tasks: install-docker-compose.yml tags: install docker-compose when: gitlabrunner - import_tasks: docker_proxy.yaml tags: use docker proxy when: proxy when: gitlabrunner - import_tasks: gitlab-registry.yml tags: Install gitlab-registry - import_tasks: gitlab-runner-install.yml tags: Install gitlab-runner when: gitlabrunner |
[/codesyntax]