Ansible Conditions
Jump to navigation
Jump to search
Conditions
When
---
- name: Install Apache WebServer
hosts: localhost
tasks:
- name: Install Apache on Ubuntu Server
apt-get:
name: apache2
state: present
when: ansible_os_family == “Ubuntu“
- name: Install Apache on CentOS Server
yum:
name: httpd
state: present
when: ansible_os_family == "RedHat"
ansible_os_family is a built in variable
you can get a list of all ansible built in variables by running
ansible localhost -m setup