准备zk需要的zoo.cfg 和 myid 文件
[root@10.0.0.11 root]# cd templates/kafka/
[root@10.0.0.11 root]# ls
myid1 myid2 myid3 zoo.cfg
1.编辑主角色文件
vim install-zk.yml
---
- hosts: '{{ target }}'
vars:
host1: 10.0.0.11
host2: 10.0.0.12
host3: 10.0.0.13
tasks:
- include: tasks/install-zk.yml
** 2.编辑tasks文件**
vim tasks/install-zk.yml
---
- name: copy zookeeper-3.4.12.tar.gz
copy: src=files/kafka/zookeeper-3.4.12.tar.gz dest=/opt/
- name: tar zookeeper-3.4.12.tar.gz
shell: tar xf /opt/zookeeper-3.4.12.tar.gz -C /opt/
- name: mv zookeeper
shell: mv -f /opt/zookeeper-3.4.12 /opt/zookeeper
- name: chenge zk-zoo.cfg,kafka-server.properties
template: "src={{ item.src }} dest={{ item.dest }} mode=0644"
with_items:
- { src: 'kafka/zoo.cfg',dest: '/opt/zookeeper/conf/zoo.cfg' }
- name: zk-server1
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: '^server.1='
line: 'server.1={{ host1 }}:2888:3888'
- name: zk-server2
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: '^server.2='
line: 'server.2={{ host2 }}:2888:3888'
- name: zk-server3
lineinfile:
dest: /opt/zookeeper/conf/zoo.cfg
regexp: '^server.3='
line: 'server.3={{ host3 }}:2888:3888'
- name: mkdir file
file: dest={{ item }} state=directory mode=0755
with_items:
- /data/zookeeper/data
- /data/zookeeper/logs
- name: sync zkmyid1 file
template: src=kafka/myid1 dest=/data/zookeeper/data/myid
when: ansible_nodename == '{{ host1 }}'
- name: sync zkmyid2 file
template: src=kafka/myid2 dest=/data/zookeeper/data/myid
when: ansible_nodename == '{{ host2 }}'
- name: sync zkmyid3 file
template: src=kafka/myid3 dest=/data/zookeeper/data/myid
when: ansible_nodename == '{{ host3 }}'
- name: rm tar
shell: rm -f /opt/zookeeper-3.4.12.tar.gz
#还有好多需要进步,记录下来自己成长过程!!共勉