Skip to content

Conversation

@armitageee
Copy link

@armitageee armitageee commented May 13, 2023

Request

Для запуска плейбуков потребуется 3 виртуальные машины + мастер сервер с Ansible, в инвентори файле надо заменить ip адреса на свои, и добавить ip адрес машины в telegraf.conf на которой будет размещен mqtt broker.

Пароль для ssh и sudo были созданы в виде отдельных переменных в ansible_vault

После чего запускаем плейбук из директории с плейбуком следующей командой

ansible-playbook deploy-playbook.yml -i inventory.ini --ask-vault-pass --extra-vars '@{имя vault файла}'

После того, как все развернулось можно использовать плейбук compose_down_playbook.yml для выключения всей инфраструктуры:
ansible-playbook compose_down_playbook.yml -i inventory.ini --ask-vault-pass --extra-vars '@{имя vault файла}'

Copy link
Owner

@antonaleks antonaleks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pycache папки нужно удалить из репы

@@ -0,0 +1,82 @@
- hosts: server
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нейминг файлов отличается. придерживайся одного принципа. либо через - либо через _


tasks:

- docker_host_info:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для каждой таски можно добавить name и написать небольшое описание что она делает. считай сразу пишешь документацию

pkg: "{{packages}}"
state: latest

# - name: import netplan cfg for gateway
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такие рудементы не стоит хранить в публичной репе


tasks:

- name: installing packages
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

везде добавь name с описанием таски

become: yes
become_method: sudo
vars:
packages:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

все одинаковые таски просятся быть оформленными в роли. На самом деле на всех тачках ты делаешь одни и те же действия - ставишь докер и докер композ, запускаешь docker compose up. просто разные файлики и параметры

по сути пишется одна две роли и инклудятся в разные тачки. сейчас у тебя много дублирования

ansible_ssh_pass = '{{my_ssh_pass}}'
ansible_sudo_pass= '{{my_cluster_sudo_pass}}'
[server_host]
server ansible_host=192.168.0.167 ansible_ssh_user=armitage ansible_become=true StrictHostKeyChecking=no
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_ssh_pass
ansible_sudo_pass
ansible_ssh_user
ansible_become
можно вынести в общие переменные для всех серверов. например в cluster:vars

@@ -0,0 +1,9 @@
network:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это стоит оформить в виде темплейта с конфигурируемыми адресами

@@ -0,0 +1,24 @@
version: "3"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

композ файлы можно также оформить в виде темплейта

# "sensors/#",
# ]
servers = ["tcp://192.168.26.1:1883"] # адрес vm с mqtt-брокером
servers = ["tcp://192.168.0.144:1883"] # адрес vm с mqtt-брокером
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

конфиг можно сделать в виде темплейта с конфигурируемым айпи

@antonaleks antonaleks added the good first issue Good for newcomers label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants