homework 8.4: partially complete

This commit is contained in:
2022-08-01 10:45:28 +07:00
parent fbece247aa
commit 0115945805
10 changed files with 201 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
inventory/prod.yml
files/*

View File

@@ -0,0 +1,8 @@
---
clickhouse_version: "22.3.3.44"
clickhouse_dbs_custom:
- { "name": logs }
clickhouse_packages:
- clickhouse-client
- clickhouse-server
- clickhouse-common-sta

View File

@@ -0,0 +1,6 @@
---
nginx_username: dannc
lighthouse_vcs: https://github.com/VKCOM/lighthouse.git
lighthouse_vcs_version: d701335c25cd1bb9b5155711190bad8ab852c2ce
lighthouse_location: /var/www/lighthouse
lighthouse_access_log_name: lighthouse

View File

@@ -0,0 +1,6 @@
---
vector_version: 0.23.0
vector_config_dir: /var/lib/vector
vector_config:
data_dir: /var/lib/vector
# todo добавить конфигурацию https://vector.dev/docs/reference/configuration/

View File

@@ -0,0 +1,13 @@
---
clickhouse:
hosts:
clickhouse-01:
ansible_host: <IP_here>
vector:
hosts:
vector-01:
ansible_host: <IP_here>
lighthouse:
hosts:
lighthouse-01:
ansible_host: <IP_here>

View File

@@ -0,0 +1,9 @@
---
- src: git@github.com:AlexeySetevoi/ansible-clickhouse.git
scm: git
version: "1.13"
name: clickhouse
- src: git@github.com:Dannecron/netology-devops-ansible-lighthouse.git
scm: git
version: "1.0.1"
name: lighthouse

View File

@@ -0,0 +1,78 @@
---
- name: clickhouse
hosts: clickhouse
roles:
- clickhouse
tags:
- clickhouse
- name: lighthouse
hosts: lighthouse
roles:
- lighthouse
tags:
- lighthouse
- name: vector
hosts: vector
tasks:
- name: vector | install archive manager
become: true
ansible.builtin.yum:
name:
- tar
- name: vector | get distrib
ansible.builtin.get_url:
url: "https://packages.timber.io/vector/{{ vector_version }}/vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
dest: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
mode: "755"
- name: vector | unpack distrib
ansible.builtin.unarchive:
src: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
dest: "./"
remote_src: true
- name: vector | install
become: true
ansible.builtin.copy:
src: "vector-x86_64-unknown-linux-musl/bin/vector"
dest: "/usr/local/bin/"
remote_src: true
mode: "755"
- name: vector | check installed version
ansible.builtin.command:
cmd: vector --version
register: result
changed_when:
- 'vector_version not in result.stdout'
tags:
- vector_check_version
- name: vector | create data dir
become: true
ansible.builtin.file:
mode: "755"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_gid }}"
path: "{{ vector_config_dir }}"
state: "directory"
- name: vector | template config
ansible.builtin.template:
src: "templates/vector.config.j2"
dest: "{{ vector_config_dir }}/vector.yaml"
mode: "755"
- name: vector | register as service
become: true
ansible.builtin.template:
src: "templates/vector.service.j2"
dest: "/etc/systemd/system/vector.service"
owner: "{{ ansible_user_id }}"
group: "{{ ansible_user_gid }}"
mode: "0644"
backup: true
- name: vector | start service
become: true
ansible.builtin.service:
name: vector
state: started
daemon_reload: true
tags:
- vector

View File

@@ -0,0 +1,77 @@
Выполнение [домашнего задания](https://github.com/netology-code/mnt-homeworks/blob/MNT-13/08-ansible-04-role/README.md)
по теме "8.4. Работа с Roles".
## Q/A
### Задание 1
> Подготовка к выполнению
>
> 1. (Необязательно) Познакомьтесь с [lighthouse](https://youtu.be/ymlrNlaHzIY?t=929)
> 2. Создайте два пустых публичных репозитория в любом своём проекте: vector-role и lighthouse-role.
> 3. Добавьте публичную часть своего ключа к своему профилю в github.
Заведены новые репозитории:
- //todo vector
- [Dannecron/netology-devops-ansible-lighthouse](https://github.com/Dannecron/netology-devops-ansible-lighthouse)
### Задание 2
> Основная часть
>
> Наша основная цель - разбить наш playbook на отдельные roles.
> Задача: сделать roles для clickhouse, vector и lighthouse и написать playbook для использования этих ролей.
> Ожидаемый результат: существуют три ваших репозитория: два с roles и один с playbook.
>
> 1. Создать в старой версии playbook файл `requirements.yml` и заполнить его следующим содержимым:
>
> ```yaml
> ---
> - src: git@github.com:AlexeySetevoi/ansible-clickhouse.git
> scm: git
> version: "1.11.0"
> name: clickhouse
> ```
Создан файл [requirements.yml](./playbook/requirements.yml).
> 2. При помощи `ansible-galaxy` скачать себе эту роль.
```shell
ansible-galaxy install -r requirements.yml
```
```text
Starting galaxy role install process
- extracting clickhouse to ~/.ansible/roles/clickhouse
- clickhouse (1.13) was installed successfully
```
__Warning__: Внутри роли используются тэги `always`, которые нужно игнорировать (`--skip-tags always`),
если данная роль не будет запускаться в рамках playbook.
> 4. Создать новый каталог с ролью при помощи `ansible-galaxy role init vector-role`.
> 5. На основе tasks из старого playbook заполните новую role. Разнесите переменные между `vars` и `default`.
> 6. Перенести нужные шаблоны конфигов в `templates`.
> 7. Описать в `README.md` обе роли и их параметры.
// todo сделать для vector
> 9. Повторите шаги 3-6 для lighthouse. Помните, что одна роль должна настраивать один продукт.
Новая роль создана и расположена в репозитории [Dannecron/netology-devops-ansible-lighthouse](https://github.com/Dannecron/netology-devops-ansible-lighthouse).
Плюс, добавлена новая зависимость в [requirements.yml](./playbook/requirements.yml):
```yaml
- src: git@github.com:Dannecron/netology-devops-ansible-lighthouse.git
scm: git
version: "1.0.1"
name: lighthouse
```
> 11. Выложите все roles в репозитории. Проставьте тэги, используя семантическую нумерацию. Добавьте roles в `requirements.yml` в playbook.
> 12. Переработайте playbook на использование roles. Не забудьте про зависимости lighthouse и возможности совмещения `roles` с `tasks`.
> 13. Выложите playbook в репозиторий.
[Playbook](./playbook/site.yml) был переработан на использование ролей.