提交各组件部署Ansible剧本初版
This commit is contained in:
5
CMAK/3.0.0.6/cmak/hosts
Normal file
5
CMAK/3.0.0.6/cmak/hosts
Normal file
@@ -0,0 +1,5 @@
|
||||
[zookeeper]
|
||||
192.168.45.102
|
||||
|
||||
[kafka]
|
||||
192.168.45.102
|
||||
7
CMAK/3.0.0.6/cmak/install.yml
Normal file
7
CMAK/3.0.0.6/cmak/install.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- hosts: kafka
|
||||
remote_user: root
|
||||
roles:
|
||||
- role
|
||||
vars_files:
|
||||
- role/vars/main.yml
|
||||
|
||||
6
CMAK/3.0.0.6/cmak/role/defaults/main.yml
Normal file
6
CMAK/3.0.0.6/cmak/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
|
||||
|
||||
5
CMAK/3.0.0.6/cmak/role/files/kafka_client_jaas.conf
Normal file
5
CMAK/3.0.0.6/cmak/role/files/kafka_client_jaas.conf
Normal file
@@ -0,0 +1,5 @@
|
||||
KafkaClient {
|
||||
org.apache.kafka.common.security.plain.PlainLoginModule required
|
||||
username="admin"
|
||||
password="galaxy2019";
|
||||
};
|
||||
24
CMAK/3.0.0.6/cmak/role/handlers/main.yml
Normal file
24
CMAK/3.0.0.6/cmak/role/handlers/main.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
- 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
|
||||
34
CMAK/3.0.0.6/cmak/role/tasks/deploy.yml
Normal file
34
CMAK/3.0.0.6/cmak/role/tasks/deploy.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
- name: Creating directory
|
||||
file:
|
||||
state: directory
|
||||
path: '{{ deploy_dir }}/{{ container_name }}/conf'
|
||||
|
||||
- name: Copying image to {{ deploy_dir }}/{{ container_name }}/
|
||||
copy:
|
||||
src: 'files/kafka_client_jaas.conf'
|
||||
dest: '{{ deploy_dir }}/{{ container_name }}/conf/kafka_client_jaas.conf'
|
||||
force: true
|
||||
|
||||
- name: Create CMAK in zookeeper nodes
|
||||
shell: docker exec zookeeper zkCli.sh create /kafka-manager "" && docker exec zookeeper zkCli.sh create /kafka-manager/mutex "" && docker exec zookeeper zkCli.sh create /kafka-manager/mutex/locks "" && docker exec zookeeper zkCli.sh create /kafka-manager/mutex/leases ""
|
||||
run_once: true
|
||||
delegate_to: "{{ groups.zookeeper[0] }}"
|
||||
|
||||
- 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:
|
||||
- Loading Image
|
||||
- Start Container
|
||||
|
||||
- meta: flush_handlers
|
||||
9
CMAK/3.0.0.6/cmak/role/tasks/main.yml
Normal file
9
CMAK/3.0.0.6/cmak/role/tasks/main.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
- block:
|
||||
- include: unload.yml
|
||||
- include: deploy.yml
|
||||
- include: status-check.yml
|
||||
when: (operation) == "install"
|
||||
|
||||
- block:
|
||||
- include: unload.yml
|
||||
when: (operation) == "uninstall"
|
||||
13
CMAK/3.0.0.6/cmak/role/tasks/status-check.yml
Normal file
13
CMAK/3.0.0.6/cmak/role/tasks/status-check.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
- name: Waitting for cmak running,30s
|
||||
shell: sleep 30
|
||||
|
||||
- name: Check if the Kafka already exists
|
||||
shell: netstat -anlp | grep "9998" | grep java | grep LISTEN | wc -l
|
||||
register: port_out
|
||||
|
||||
- name: To terminate execution
|
||||
fail:
|
||||
msg: "CMAK on node {{ inventory_hostname }} is not started. Please check"
|
||||
run_once: true
|
||||
delegate_to: 127.0.0.1
|
||||
when: port_out.stdout != '1'
|
||||
28
CMAK/3.0.0.6/cmak/role/tasks/unload.yml
Normal file
28
CMAK/3.0.0.6/cmak/role/tasks/unload.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
- 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: Ansible delete old {{ deploy_dir }}/{{ container_name }}
|
||||
file:
|
||||
path: '{{ deploy_dir }}/{{ container_name }}'
|
||||
state: absent
|
||||
|
||||
- name: Checking ZooKeeper has Kafka nodes
|
||||
shell: "docker exec -it zookeeper zkCli.sh ls / | grep kafka-manager | wc -l"
|
||||
run_once: true
|
||||
delegate_to: "{{ groups.zookeeper[0] }}"
|
||||
register: has_zknode
|
||||
|
||||
- name: Delete Kafka nodes in ZooKeeper
|
||||
shell: "docker exec -it zookeeper zkCli.sh rmr /kafka-manager"
|
||||
run_once: true
|
||||
delegate_to: "{{ groups.zookeeper[0] }}"
|
||||
when: has_zknode.stdout >= '1'
|
||||
24
CMAK/3.0.0.6/cmak/role/templates/docker-compose.yml.j2
Normal file
24
CMAK/3.0.0.6/cmak/role/templates/docker-compose.yml.j2
Normal file
@@ -0,0 +1,24 @@
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
cmak:
|
||||
image: {{ image_name }}:{{ image_tag }}
|
||||
container_name: {{ container_name }}
|
||||
restart: always
|
||||
command:
|
||||
- "-Dhttp.port=9998"
|
||||
- "-Dcmak.zkhosts={% for dev_info in groups.zookeeper -%}
|
||||
{% if loop.last -%}
|
||||
{{dev_info}}:2181
|
||||
{%- else %}
|
||||
{{dev_info}}:2181,
|
||||
{%- endif %}
|
||||
{%- endfor %}"
|
||||
- "-DbasicAuthentication.enabled=true"
|
||||
- "-DbasicAuthentication.username={{ cmak_default_username }}"
|
||||
- "-DbasicAuthentication.password={{ cmak_default_pin }}"
|
||||
- "-Djava.security.auth.login.config=/cmak/conf/kafka_client_jaas.conf"
|
||||
volumes:
|
||||
- "{{ deploy_dir }}/{{ container_name }}/conf/kafka_client_jaas.conf:/cmak/conf/kafka_client_jaas.conf"
|
||||
- "{{ deploy_dir }}/{{ container_name }}/logs:/cmak/logs"
|
||||
network_mode: "host"
|
||||
9
CMAK/3.0.0.6/cmak/role/vars/main.yml
Normal file
9
CMAK/3.0.0.6/cmak/role/vars/main.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
#镜像名称
|
||||
image_name: cmak
|
||||
|
||||
#镜像版本号
|
||||
image_tag: 3.0.0.6
|
||||
|
||||
#容器名称
|
||||
container_name: cmak
|
||||
|
||||
Reference in New Issue
Block a user