提交各组件部署Ansible剧本初版
This commit is contained in:
3
Pushgateway/1.4.2/pushgateway/hosts
Normal file
3
Pushgateway/1.4.2/pushgateway/hosts
Normal file
@@ -0,0 +1,3 @@
|
||||
[pushgateway]
|
||||
192.168.45.102
|
||||
|
||||
7
Pushgateway/1.4.2/pushgateway/install.yml
Normal file
7
Pushgateway/1.4.2/pushgateway/install.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- hosts: pushgateway
|
||||
remote_user: root
|
||||
roles:
|
||||
- role
|
||||
vars_files:
|
||||
- role/vars/main.yml
|
||||
|
||||
6
Pushgateway/1.4.2/pushgateway/role/defaults/main.yml
Normal file
6
Pushgateway/1.4.2/pushgateway/role/defaults/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
#The default installation location
|
||||
deploy_dir: /data/olap
|
||||
|
||||
#The default data storage location,use storing application data,logs and configuration files
|
||||
data_dir: /data/olap
|
||||
|
||||
25
Pushgateway/1.4.2/pushgateway/role/handlers/main.yml
Normal file
25
Pushgateway/1.4.2/pushgateway/role/handlers/main.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
- name: Loading Image
|
||||
docker_image:
|
||||
name: '{{ image_name }}'
|
||||
tag: '{{ image_tag }}'
|
||||
load_path: '{{ deploy_dir }}/{{ container_name }}/{{ image_name }}-{{ image_tag }}.tar'
|
||||
source: load
|
||||
force_tag: yes
|
||||
force_source: yes
|
||||
timeout: 300
|
||||
|
||||
- name: Stop Container
|
||||
docker_container:
|
||||
name: '{{ container_name }}'
|
||||
state: absent
|
||||
|
||||
- name: Start Container
|
||||
docker_compose:
|
||||
project_src: '{{ deploy_dir }}/{{ container_name }}/'
|
||||
|
||||
- name: Removing Image
|
||||
docker_image:
|
||||
name: '{{ image_name }}'
|
||||
tag: '{{ image_tag }}'
|
||||
state: absent
|
||||
|
||||
22
Pushgateway/1.4.2/pushgateway/role/tasks/deploy.yml
Normal file
22
Pushgateway/1.4.2/pushgateway/role/tasks/deploy.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
- name: Creating directory
|
||||
file:
|
||||
state: directory
|
||||
path: '{{ deploy_dir }}/{{ container_name }}'
|
||||
|
||||
- name: Copying image to {{ deploy_dir }}/{{ container_name }}/
|
||||
copy:
|
||||
src: 'files/{{ image_name }}-{{ image_tag }}.tar'
|
||||
dest: '{{ deploy_dir }}/{{ container_name }}/'
|
||||
force: true
|
||||
notify:
|
||||
- Loading Image
|
||||
|
||||
- name: Copying Kafka config files
|
||||
template:
|
||||
src: 'docker-compose.yml.j2'
|
||||
dest: '{{ deploy_dir }}/{{ container_name }}/docker-compose.yml'
|
||||
mode: 0644
|
||||
notify:
|
||||
- Start Container
|
||||
|
||||
- meta: flush_handlers
|
||||
10
Pushgateway/1.4.2/pushgateway/role/tasks/main.yml
Normal file
10
Pushgateway/1.4.2/pushgateway/role/tasks/main.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
- block:
|
||||
- include: uninstall.yml
|
||||
- include: deploy.yml
|
||||
- include: status-check.yml
|
||||
when: (operation) == "install"
|
||||
|
||||
- block:
|
||||
- include: uninstall.yml
|
||||
when: (operation) == "uninstall"
|
||||
|
||||
17
Pushgateway/1.4.2/pushgateway/role/tasks/status-check.yml
Normal file
17
Pushgateway/1.4.2/pushgateway/role/tasks/status-check.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- name: Waitting for Pushgateway running,30s
|
||||
shell: sleep 30
|
||||
|
||||
- name: Check if the Pushgateway already exists
|
||||
shell: ps -ef | grep pushgateway |grep -v grep | wc -l
|
||||
register: process_out
|
||||
|
||||
- name: Check if the Pushgateway already exists
|
||||
shell: netstat -anlp | egrep "9091" | grep LISTEN | wc -l
|
||||
register: port_out
|
||||
|
||||
- name: To terminate execution
|
||||
fail:
|
||||
msg: "Kafka on node {{ inventory_hostname }} is not started. Please check"
|
||||
run_once: true
|
||||
delegate_to: 127.0.0.1
|
||||
when: process_out.stdout != '1' or port_out.stdout != '1'
|
||||
27
Pushgateway/1.4.2/pushgateway/role/tasks/uninstall.yml
Normal file
27
Pushgateway/1.4.2/pushgateway/role/tasks/uninstall.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
- block:
|
||||
- name: Stopping and removing {{ container_name }} container
|
||||
docker_container:
|
||||
name: '{{ container_name }}'
|
||||
state: absent
|
||||
|
||||
- name: Removing old {{ image_name }} image
|
||||
docker_image:
|
||||
name: '{{ image_name }}'
|
||||
tag: '{{ image_tag }}'
|
||||
state: absent
|
||||
|
||||
- name: Stopping and removing exporter container
|
||||
docker_container:
|
||||
name: 'kafka_exporter'
|
||||
state: absent
|
||||
|
||||
- name: Removing old exporter image
|
||||
docker_image:
|
||||
name: 'kafka_exporter'
|
||||
tag: 'v2.0'
|
||||
state: absent
|
||||
|
||||
- name: Ansible delete old {{ deploy_dir }}/{{ container_name }}
|
||||
file:
|
||||
path: '{{ deploy_dir }}/{{ container_name }}'
|
||||
state: absent
|
||||
@@ -0,0 +1,15 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
pushgateway:
|
||||
image: {{ image_name }}:{{ image_tag }}
|
||||
container_name: {{ container_name }}
|
||||
ports:
|
||||
- 9091:9091
|
||||
networks:
|
||||
olap:
|
||||
ipv4_address: 172.20.88.12
|
||||
networks:
|
||||
olap:
|
||||
external: true
|
||||
|
||||
BIN
Pushgateway/1.4.2/pushgateway/role/vars/.main.yml.swp
Normal file
BIN
Pushgateway/1.4.2/pushgateway/role/vars/.main.yml.swp
Normal file
Binary file not shown.
11
Pushgateway/1.4.2/pushgateway/role/vars/main.yml
Normal file
11
Pushgateway/1.4.2/pushgateway/role/vars/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
#镜像名称
|
||||
image_name: pushgateway
|
||||
|
||||
#镜像版本号
|
||||
image_tag: 1.4.2
|
||||
|
||||
#容器名称
|
||||
container_name: pushgateway
|
||||
|
||||
#组件版本
|
||||
component_version: pushgateway-1.4.2
|
||||
Reference in New Issue
Block a user