ansible-playbook基础使用(二)

一、playbook基本格式如下

[ ansible]# cat file.yaml 
---
  # 主机
- hosts: date
  # 用户
  remote_user: root
  
  # 任务
  tasks:
    - name: create new_file
      file: name=/data/newfile state=touch
    - name: create new_user
      user: name=test2 system=yes shell=/sbin/nologin
    - name: install package
      yum: name=httpd
    - name: copy html
      copy: src=/data/html.html dest=/data/html.html
    - name: start service
      service: name=httpd state=started enabled=yes

检查语法

ansible-playbook -C file.yaml

没有问题执行

ansible-playbook  file.yaml

ansible-playbook基础使用(二)

 二、ansible-playbook 、ansible通用命令

[ ansible]# ansible-playbook file.yaml --list-host

playbook: file.yaml

  play #1 (date): date	TAGS: []
    pattern: [u‘date‘]
    hosts (3):
      192.168.56.11
      192.168.56.12
      192.168.56.13
[ ansible]# ansible-playbook file.yaml --list-tag

playbook: file.yaml

  play #1 (date): date	TAGS: []
      TASK TAGS: []

相关推荐