ct38 发表于 2018-1-2 13:34:38

Ⅰ. Playbook介绍

# cat test.yml  

---  
- hosts: all   #指定所有主机组
  vars:          #指定变量
  http_dir: /etc/httpd/conf
  remote_user: root #指定root执行
  tasks:
  - name: Install NTP #安装NTP服务
  yum: name=ntp state=installed
  - name: Enable NTP #开启NTP服务
  service: name=ntpd state=started enabled=yes
  

  - name: CP files #通过执行cp语句拷贝文件
  command: cp /etc/hosts /etc/hosts.bk
  

  - name: copy module #通过copy module复制配置文件
  copy:
  src: "{{ item.src }}"
  dest: "{{ item.dest }}"
  owner: root
  group: root
  mode: 0644
  with_items:
  - {
  src: "/tmp/httpd.conf",
  dest: "/etc/httpd/conf/httpd.conf"
  }
  - {
  src: "/tmp/httpd-vhosts.conf",
  dest: "/etc/httpd/conf/httpd-vhosts.conf"
  }
  

  - name: copy file and restart httpd #备份文件,成功后通过notify触发handlers重启HTTPD
  copy: "src={{http_dir}}/httpd.conf dest=/tmp/httpd.conf.bk"
  notify:
  - restart httpd service
  handlers:
  -name: restart httpd service
  service: name=httpd state=restarted
页: [1]
查看完整版本: Ⅰ. Playbook介绍