1. 安装epel yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 2. 安装ansible yum install ansible 3. 建立role mkdir -p /opt/ansible-playbook/roles mkdir -p {elasticsearch,redis}/{default,files,handlers,meta,tasks,templates,vars} 4. 添加被管理主机登录key vi config Host 192.168.*.* User ec2-user IdentityFile ~/.ssh/testing_server.pem 5. 添加hosts [redis_testing] 192.168.1.190 [canal_testing] 192.168.1.191 [es_testing] 192.168.1.192 [coes_testing] 192.168.1.194 [kafka_testing] 192.168.1.195 [all_testing:children] redis_testing canal_testing es_testing coes_testing kafka_testing [all_testing:vars] ansible_ssh_port = 22 6. 测试 ansible all_testing -m shell -a 'pwd' 7. 建立tasks cd /opt/ansible-playbook/roles/redis/tasks - name: Create dir to keep install file file: path=/opt/pacheage state=directory follow=yes force=yes - name: Copy install file copy: src=redis-{{ redis_version }}.tar.gz dest=/opt/pacheage/ - name: Delete last time unarchive file: path=/opt/pacheage/redis-{{ redis_version }} state=absent - name: Unarchive install file unarchive: src=/opt/pacheage/redis-{{ redis_version }}.tar.gz dest=/opt/pacheage copy=no - name: Install dependent package yum: name: - gcc - tcl state: present - name: Delete last time install dir file: path=/opt/redis-{{ redis_version }} state=absent - name: Install redis shell: cd /opt/pacheage/redis-{{ redis_version }} && make PREFIX=/opt/redis-{{ redis_version }}/ install - name: Mkdir /opt/redis-{{ redis_version }}/data,conf,log file: path=/opt/redis-{{ redis_version }}/{{ item }} state=directory follow=yes force=yes with_items: - data - conf - log - name: Copy redis.conf file template: src=redis.conf.j2 dest=/opt/redis-{{ redis_version }}/conf/ - name: Start redis shell: /opt/redis-{{ redis_version }}/bin/redis-server /opt/redis-{{ redis_version }}/conf/redis.conf &