如何过滤OS类别
ansible_os_family
- CentOS
--- - name: Gather facts and filter CentOS hosts hosts: os_version gather_facts: true tasks: - name: Check CentOS hosts assert: that: - ansible_os_family == 'RedHat' fail_msg: "Non-CentOS host: {{ inventory_hostname }}" success_msg: "CentOS host: {{ inventory_hostname }}" changed_when: false
-
Ubuntu
--- - name: Gather facts and filter Ubuntu hosts hosts: os_version gather_facts: true tasks: - name: Check Ubuntu hosts assert: that: - ansible_os_family == 'Debian' fail_msg: "Non-Ubuntu host: {{ inventory_hostname }}" success_msg: "Ubuntu host: {{ inventory_hostname }}" changed_when: false
ansible_distribution
- CentOS
--- - name: Gather facts and filter CentOS hosts hosts: os_version gather_facts: true tasks: - name: Check CentOS hosts assert: that: - ansible_distribution == 'CentOS' fail_msg: "Non-CentOS host: {{ inventory_hostname }}" success_msg: "CentOS host: {{ inventory_hostname }}" changed_when: false
- Ubuntu
--- - name: Gather facts and filter Ubuntu hosts hosts: os_version gather_facts: true tasks: - name: Check Ubuntu hosts assert: that: - ansible_distribution == 'Ubuntu' fail_msg: "Non-Ubuntu host: {{ inventory_hostname }}" success_msg: "Ubuntu host: {{ inventory_hostname }}" changed_when: false