Найти тему
WindowsProfs

destroy app

apt-get install git

git clone https://github.com/auteam-usr/moscow39.git

cd moscow39

docker build -t localhost:5000/app1:latest .

docker push localhost:5000/app1:latest

шаблон конфигурации балансировщика: /home/altlinux/haproxy.cfg

frontend https
bind *:80
bind *:443 ssl crt /etc/haproxy/server.pem
http-request redirect scheme https unless { ssl_fc }
default_backend app1
backend app1
balance roundrobin
server web1 10.1.1.1:80 check
server web2 10.1.1.2:80 check

apt-get install ansible
Inventory: /etc/ansible/hosts

[Balancer]

интернет_адрес_балансировщика

[Webs]

интернет_адрес_веб1

интернет_адрес_веб2

Плейбук: /etc/ansible/infra.yml

- name: Haproxy tasks
hosts: Balancer
tasks:
- name: Install haproxy
apt_rpm:
name: haproxy
state: present
update_cache: yes
- name: Copy cert
copy:
src=/home/altlinux/server.pem
dest=/etc/haproxy/server.pem
- name: Config haproxy
blockinfile:
dest: /etc/haproxy/haproxy.cfg
block: "{{ lookup('file', '/home/altlinux/haproxy.cfg.tpl') }}"
- name: Restart HAproxy
ansible.builtin.service:
name: haproxy
state: restarted
- name: Docker tasks
hosts: Webs
tasks:
- name: Install docker
apt_rpm:
name: docker-engine
state: present
update_cache: yes
- name: json edit
lineinfile:
path: "/etc/docker/daemon.json"
regexp: '^{$'
line: '{"insecure-registries" : [ "172.16.99.2:5000" ],'
- name: Restart docker
ansible.builtin.service:
name: docker
state: restarted

- name: run app1
command: docker run -p 80:80 -d --restart always 172.16.99.2:5000/app1:latest

в
/home/altlinux/DeployApp.sh:

#!/bin/bash
rm /home/altlinux/.ssh/known_hosts
rm /root/.ssh/known_hosts
ssh-keyscan -f /home/altlinux/servers.ip
ssh-keyscan -f /home/altlinux/lb.ip
echo [Balancer] > /etc/ansible/hosts
cat /home/altlinux/lb.ip >> /etc/ansible/hosts
echo -e "\n" >> /etc/ansible/hosts
echo [Webs] >> /etc/ansible/hosts
cat /home/altlinux/servers.ip >> /etc/ansible/hosts
ansible-playbook /etc/ansible/infra.yml -i /etc/ansible/hosts

chmod +x /home/altlinux/bin/DeployApp.sh

Чтобы проверить, удаляем машины через:

terraform destroy(нужно быть в /home/altlinux)

Создаём все задания двумя скриптами:

cloudinit.sh

DeployApp.sh