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
  • 相关阅读:
    C# 代理与事件上(delegate)
    串口编程(SerialPort类)
    java提取QQ邮箱中的邮箱地址
    javascript 调用onclick动作的几种方式。
    python的一些扩展模块,关于Reserving的....
    [ZZ]硬件虚拟化漫谈
    Intel VTx 技术手册 目录
    VTx技术手册杂记
    关于磁盘分析的一些资料
    ReactOS下的Sysutils目录.
  • 原文地址:https://www.cnblogs.com/shykoo/p/10559392.html
Copyright © 2011-2022 走看看