• ansible on aws linux 2


    
    

      

    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 &
    

      

  • 相关阅读:
    Android.mk简介
    signal函数的原型声明void (*signal(int signo, void (*fun(int))))(int)分析
    关于fork()函数的精辟分析
    [Ubuntu]win10卸载ubuntu
    [Shell]清空文件内容 | 使用curl进行post请求
    【Shell】在字符串中引用变量
    [Jenkins]视图
    [Jenkins]执行git push命令报错fatal: could not read Username forxxx| 配置jenkins使用ssh方式连接git
    [MAC]Permission denied, please try again.
    [Shell] 函数的应用
  • 原文地址:https://www.cnblogs.com/divl/p/11065136.html
Copyright © 2020-2023  润新知