zoukankan      html  css  js  c++  java
  • ansible的roles角色

    创建树状目录
    [root@zxw8 ~]# mkdir -pv playbook/roles/{dbservers,webservers}/{files,handlers,tasks,templates,vars}
    本地安装tree
    [root@zxw8 ~]# cd Packages/
    [root@zxw8 ~]# rpm -ivh tree-1.6.0-10.el7.x86_64.rpm
    yum安装
    [root@zxw8 ~]# yum install tree -y
    查看playbook
    [root@zxw8 ~]# tree playbook/
    playbook/
    └── roles
    ├── dbservers
    │   ├── files
    │   ├── handlers
    │   ├── tasks
    │   ├── templates
    │   └── vars
    └── webservers
    ├── files
    ├── handlers
    ├── tasks
    ├── templates
    └── vars
    创建任务tasks
    [root@zxw8 playbook]# vim roles/dbservers/tasks/main.yaml
    - name: service httpd restarted
    service: name=httpd state=restarted
    - name: touch file
    command: touch /root/a.txt
    [root@zxw8 playbook]# ls
    Roles
    创建执行任务的角色roles
    [root@zxw8 playbook]# vim site.yaml
    - hosts: zxw
    remote_user: root
    roles:
    - dbservers
    [root@zxw8 playbook]# ansible-playbook site.yaml
    复制文件files
    [root@zxw8 playbook]# cp /etc/httpd/conf/httpd.conf roles/dbservers/files/
    [root@zxw8 playbook]# vim roles/dbservers/tasks/main.yaml

    - name: service httpd restarted
    service: name=httpd state=restarted
    - name: touch file
    command: touch /root/a.txt
    - name: cp httpd.conf
    copy: src=httpd.conf dest=/etc/httpd/conf/httpd.conf

    变量定义vars
    [root@zxw8 playbook]# vim roles/dbservers/vars/main.yaml

    file: httpd.conf

    触发器:handlers
    [root@zxw8 playbook]# vim roles/dbservers/tasks/main.yaml

    - name: service httpd restarted
    service: name=httpd state=restarted
    - name: touch file
    command: touch /root/a.txt
    - name: cp httpd.conf
    copy: src={{ file }} dest=/etc/httpd/conf/{{ file }}
    notify:
    - service httpd restarted
    ~
    [root@zxw8 playbook]# vim roles/dbservers/handlers/main.yaml

    - name: service httpd restarted
    service: name=httpd state=restarted

    Templates
    [root@zxw8 playbook]# cp /etc/httpd/conf/httpd.conf roles/dbservers/templates/

    [root@zxw8 ~]# vim playbook/roles/dbservers/tasks/main.yaml

    - name: service httpd restarted
    service: name=httpd state=restarted
    - name: touch file
    command: touch /root/a.txt
    - name: cp httpd.conf
    templates: src={{ file }} dest=/etc/httpd/conf/{{ file }}
    notify:
    - service httpd restarted
    ~
    [zxw]
    192.168.126.7 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123 port=80
    192.168.126.6 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123 port=80


    [root@zxw8 ~]# tree playbook/
    playbook/
    ├── roles
    │   ├── dbservers
    │   │   ├── files
    │   │   │   └── httpd.conf
    │   │   ├── handlers
    │   │   │   └── main.yaml
    │   │   ├── tasks
    │   │   │   └── main.yaml
    │   │   ├── templates
    │   │   │   └── httpd.conf
    │   │   └── vars
    │   │   └── main.yaml
    │   └── webservers
    │   ├── files
    │   ├── handlers
    │   ├── tasks
    │   ├── templates
    │   └── vars
    └── site.yaml

     

  • 相关阅读:
    获取指定扩展名的文件 分类: python 小练习 20130514 16:06 229人阅读 评论(0) 收藏
    #遍历E盘下的mp3文件 分类: python 小练习 python 20130514 18:27 303人阅读 评论(0) 收藏
    🍖Linux输出重定向
    🍖手动添加用户
    🍗文件权限管理
    🍖文件管理之打包压缩
    🍖文件处理三剑客:sed awk grep
    🍖权限管理之用户与用户组
    🍖文件管理之字符处理 sort uniq cut tr wc
    🍖文件处理之上传下载
  • 原文地址:https://www.cnblogs.com/itzhao/p/11274007.html
Copyright © 2011-2022 走看看