zoukankan      html  css  js  c++  java
  • ansible roles 自动化安装

    例:  ansible roles 自动化安装memcached

    文件目录结构如下:

    cat memcached_role.yml

    - hosts: memcached
      remote_user: root
      
      roles:
        - memcached

    cat roles/memcached/vars/main.yml

    username: memcached
    groupname: memcached
    memcached_port: 11211

    cat roles/memcached/templates/memcached.j2

    PORT="{{ memcached_port }}"
    USER="{{ username }}"
    MAXCONN="1024"
    CACHESIZE="{{ ansible_memtotal_mb//4 }}"
    OPTIONS=""

    cat roles/memcached/handlers/main.yml

    - name: restart service
      service: name=memcached state=restarted

    cat roles/memcached/tasks/main.yml

    - import_tasks: group.yml
    - import_tasks: user.yml
    - import_tasks: yum.yml
    - import_tasks: templ.yml
    - import_tasks: copyfile.yml
    - import_tasks: start.yml

    cat roles/memcached/tasks/group.yml

    - name: create group
      group: name={{ username }} system=yes gid=11211

    cat roles/memcached/tasks/user.yml

    - name: create user
      user: name={{ username }} group={{ groupname }} uid=11211 system=yes shell=/sbin/nologin

    cat roles/memcached/tasks/yum.yml

    - name: install service
      yum: name=memcached

    cat roles/memcached/tasks/templ.yml

    - name: copy templ
      template: src=memcached.j2 dest=/etc/sysconfig/memcached
    notify: restart service

    cat roles/memcached/tasks/copyfile.yml

    - name: copy file
      copy: src=memcached.log dest=/data/ owner={{ username }}

    cat roles/memcached/tasks/start.yml

    - name: start service
      service: name=memcached enabled=yes state=started

    测试:

    ansible-playbook -C memcached_role.yml

    执行:

    ansible-playbook  memcached_role.yml
  • 相关阅读:
    MATLAB GUI制作快速入门
    JavaFX Chart设置数值显示
    Unity查找物体的四大主流方法及区别
    Matlab 图像转极坐标系
    使用python获得N个区分度较高的RGB颜色值
    Arduino学习笔记30
    Arduino学习笔记27
    Arduino学习笔记26
    Arduino学习笔记25
    Arduino学习笔记24
  • 原文地址:https://www.cnblogs.com/blogscc/p/10805219.html
Copyright © 2011-2022 走看看