zoukankan      html  css  js  c++  java
  • ansible-play中role的基本用法

    #role应用
    #roles跟调用角色的剧本文件应该与roles同级关系,即放在ansible目录下
    #makir /root/ansible/roles/{nginx,http,ftp,mysql,redis}
    palybook.yml
    roles/
        project/
            tasks/   定义task,role的基本元素,至少包含一个main.yml文件
            files/   存放由copy或script模块等调用的文件
            vars/     定义变量文件
            templates/  template模块查找所需要末班文件的目录
            handlers/
            default/  设定默认变量
    #以nginx为例
    思路:
    1.group:创建用户组nginx
    2.user:创建用户nginx
    3.yum:安装nginx
    4.template:配置文件更新nginx.conf
    5.service:启动nginx
    ####################################################################
    cd /root/ansible/roles/nginx
    mkdir tasks templates
    cd task
    
    touch group.yml
    - name: create group nginx
        group: name=nginx gid=80
    
    touch user.yml
    -name: create user nginx
        user: name=nginx uid=80 group=nginx system=yes shell=/sbi/nologin
     
    touch install.yml
    - name: install package
        yum: name=nginx
       
    touch start.yml
    - name: start service
        service: name=nginx state=started enabled=yes
        
    touch restart.yml
    - name: restart service
        service: name=nginx state=restarted
        
    touch templ.yml
    - name: copy conf
        template: src=nginx.conf.j2 dest=/etc/nginx/conf/nginx.conf
        
    touch main.yml
    - include: group.yml
    - include: user.yml
    - include: install.yml
    - include: templ.yml
    - include: start.yml
          
    cd ../templates  && ll
    nginx.conf.j2
    
    cd /root/ansible
    touch nginx_role.yml
    - hosts: websrvs
      remote_user: root
      roles:
        - role: nginx
    
    执行命令:ansible-playbook nginx_role.yml
  • 相关阅读:
    linux-kernel-module
    Linux-find
    ffmpeg02
    Redhat 7使用CentOS 7的Yum网络源
    Redhat7配置yum源(本地源和网络源)
    8、源码安装
    6.存储结构与磁盘划分
    5.用户身份与文件权限
    4.Vim编辑器与Shell命令脚本
    3.管道符、重定向与环境变量
  • 原文地址:https://www.cnblogs.com/shykoo/p/10559392.html
Copyright © 2011-2022 走看看