---
- name: condition tet
  hosts: private
  tasks:
    - name: shell command - /usr/bin/foo
      shell: python3 --version
      #shell: py3 --version
      register: result
      ignore_errors: True
    #- debug:
    #    var : ansible_facts
    - debug:
        msg : "{{ result.stderr }}"
      when: result is failed
    - debug:
        msg : "{{ result.stdout }}"
      when: result is change

---
- name: web server package install
  hosts: private 
  gather_facts: True
  become: yes
  tasks:
    - name: collect only selected facts
      setup:
        filter:
          - 'ansible_distribution'
    - debug:
        var: ansible_facts
    - name: Ubuntu - Install Apache2
      apt:
        upgrade: yes
        update_cache: yes
        name : apache2
        state: present
      ignore_errors: True
      when: ansible_facts['distribution'] == "Ubuntu"
    - name: Amazon Linux - Install httpd
      yum:
        name: httpd
        state: present
      when: ansible_facts['distribution'] == "Amazon"

필터
include( 포함 )
예시
# webserver.yml
---
- name: Install Web Server
  hosts: private
  become: yes
  gather_facts: False
  tasks:
    - name : Ubuntu - Install Apache2
      apt:
        upgrade: yes
        update_cache: yes
        name : apache2
        state: present
      ignore_errors: True
      when: ansible_facts['distribution'] == "Ubuntu"
    - name: Amazon Linux - Install httpd
      yum:
        name: httpd
        state: present
      when: ansible_facts['distribution'] == "Amazon"
# common.yml
---
- name: Install Web Server
  hosts: private
  tasks:
    - name: collect only selected facts
      setup:
        filter: 'ansible_distribution'
    #- debug :
    #    var: ansible_facts
# install_pack_web.yml
---
- import_playbook: common.yml
- import_playbook: webserver.yml

---
- name: Verify apache installation
  hosts: public
  become: yes
  gather_facts: False
  tasks:
    - name: Ensure apache is at the latest version
      yum:
        name: httpd
        state: latest
    - name: Write the apache config file
      template:
        src: ./httpd.j2
        dest: /etc/httpd.conf2
      notify:
      - Restart apache
      register: result
    - name: Ensure apache is running
      service:
        name: httpd
        state: started
      when: result is change
  handlers:
    - name: Restart apache
      service:
        name: httpd
        state: restarted