• 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

     

  • 相关阅读:
    Web API总结
    @Html.Raw() 方法输出带有html标签的字符串
    jQuery
    图与树基础-完全图的判定
    图和树基础-蒜头君旅行
    PAT乙级1008
    PAT乙级1007
    PAT乙级1005
    PAT乙级1001
    前端工程化-webpack简介(一)
  • 原文地址:https://www.cnblogs.com/itzhao/p/11274007.html
Copyright © 2020-2023  润新知