playbook语法

2018-05-31  本文已影响0人  泡面_b7f5

playbook使用yaml语法yam语法可以通过http://www.yaml.org/spec/1.2/spec.html#Syntax 了解到

讲解一个简单的例子来认识playbook代码--安装nginx

nginx.yml

旧版语法

---
- hosts: all
  tasks:
    - name: Install nginx
      yum: name=nginx state=present
    - name: template nginx.conf
      template: src=./nginx.conf.js dest=/etc/nginx/nginx.conf owner=root group=root mode=0644 validate='nginx -t -c %s'
      notify:
        - Restart Nginx Service
  handlers:
    - name: Restart Nginx Service
      service: name=nginx state=restarted

新版语法

---
- hosts: all
  tasks:
    - name: Install nginx
      yum: 
        name: nginx 
        state: present
    - name: template nginx.conf
      template: 
        src: ./nginx.conf 
        dest: /etc/nginx/nginx.conf 
        owner: root 
        group: root 
        mode: '0644'
      notify:
        - Restart Nginx Service
  handlers:
    - name: Restart Nginx Service
      service: 
        name: nginx 
        state: restarted

hosts

[nginx]
192.168.1.1

检查语法

ansible-playbook --syntax-check nginx.yaml

列出执行任务

ansible-playbook --list-task nginx.yaml

查看运行的主机

ansible-playbook --list-hosts nginx.yaml

执行

ansible-playbook nginx.yaml

上一篇下一篇

猜你喜欢

热点阅读