根据收集的事实在剧本中发起一场比赛

Launch a play in playbook based on gather facts

我有这本 Ansible Playbook,其中包含三个不同的剧本。我想做的是根据条件启动两个 last play。我如何直接在剧本级别执行此操作(不在每个角色中使用 when 子句)?

- name: Base setup
  hosts: all
  roles :
    - apt
    - pip

# !!!!! SHUT DOWN IF NOT DEBIAN DIST

- name: dbserver setup
  hosts: dbserver
  remote_user: "{{ user }}"
  become: true
  roles:
    - mariadb

- name: webserver and application setup
  hosts: webserver
  remote_user: "{{ user }}"
  become: true
  roles:
    - php
    - users
    - openssh
    - sshkey
    - gitclone
    - symfony

您可以在 pre_tasks:

中的 meta task 的帮助下结束您不想继续的主机的播放
- name: dbserver setup
  hosts: dbserver
  remote_user: "{{ user }}"
  become: true

  pre_tasks:
    - meta: end_host
      when: ansible_facts.os_family != 'Debian'

  roles:
    - mariadb

并对网络服务器执行相同的操作。