---
- hosts: testservers
  remote_user: root
  tasks:
  - name: Modify the configuration
    lineinfile:
      path=/etc/nginx/conf.d/test.conf
      regexp="Listen 80"
      line="Listen 8088"
      backrefs=yes
      backup=yes
    notify:  # 使用 notify关键字调用 handlers 中的任务
      restart nginx

  # - meta: flush_handlers  # 执行 handlers
  # ... 其他任务

  handlers:
  - name: restart nginx
    service:
      name=nginx
      state=restarted

  handlers:
  - name: handler1
    listen: handler group1  # 定义 handlers 组，notify: handler group1 即可调用该组
    file: path=/testdir/ht1
          state=touch
  - name: handler2
    listen: handler group1
    file: path=/testdir/ht2
          state=touch
