码迷,mamicode.com
首页 > 其他好文 > 详细

ansible roles 自动化安装

时间:2019-05-03 16:43:24      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:bin   hand   system   ble   http   shell   max   start   copyfile   

 

例:  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

 

ansible roles 自动化安装

标签:bin   hand   system   ble   http   shell   max   start   copyfile   

原文地址:https://www.cnblogs.com/blogscc/p/10805219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!