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

     

  • 相关阅读:
    [读书笔记]Applying UML and patterns:The agile manifesto and principles
    关于CheckBoxList和RadioButtonList的几个问题
    教你背单词
    深入剖析引用参数Ref和Out
    Web的系统测试方法 (转载)
    .net Compact Framework 程序设计起步(智能设备的程序设计)
    知道Ping的最后一个返回值TTL是什么意思吗?
    精明人的四个等级[转]
    HTTP协议下用Web Service上传大文件的解决方案
    如何解决DataGrid中删除记录后分页错误
  • 原文地址:https://www.cnblogs.com/itzhao/p/11274007.html
Copyright © 2011-2022 走看看