zoukankan      html  css  js  c++  java
  • playbook详解—YAML格式的文本

    在playbook中有一些核心的指令

    hosts:指明命令运行在哪个node之上 
    remote_user:在远端的node之上以什么用户的身份运行命令 
    var:给模板传递变量值 
    tasks:指明需要执行的命令 
    template:指明模板文件 
    handler:指明句柄所在文件目录名 
    Roles:指明需要运行的角色名

    (一)检查playbook是否正确

    ansible-playbook --syntax-check first.yml

    (二)预执行playbook

    ansible-playbook --check first.yml

    (三)查看执行命令的node节点的IP地址或主机名

    ansible-playbook --list-hosts first.yml
    first.yml
     
    - hosts: webservers
    remote_user: root
    tasks:
    - name: install httpd
    yum: name=httpd state=latest
    - name: distribute config file
    copy: src=config/httpd.conf dest=/etc/httpd/conf/httpd.conf
    tags: redistibute
    notify: restart httpd
    - name: start httpd
    service: name=httpd state=started enabled=yes
    - name: check httpd started
    shell: netstat -lntup | grep 80
     
     
    handlers:
    - name: restart httpd
    service: name=httpd state=restarted enabled=yes

    (四)使用vars定义变量

    - hosts: dbservers
    remote_user: root
    vars:
    - username: home
    - groupname: uplooking
    tasks:
    - name: add group
    group: name={{ groupname }}
    - name: add user
    user: name={{ username }} state=present
  • 相关阅读:
    2018-4-17-软件设计-白话依赖注入
    2018-2-13-wpf-PreviewTextInput-在鼠标输入获得-_u0003
    2018-5-23-为何-987654321_123456789-的值是-8.0000000729
    寄存器位写操作
    Linux多IP配置
    Kconfig和Makefile
    linux设置网卡速率
    Winmanager,NERDTree和MiniBufExplorer
    SuperTab
    ping
  • 原文地址:https://www.cnblogs.com/liu1026/p/7639720.html
Copyright © 2011-2022 走看看