when
Statements in Ansiblewhen
statement is used to conditionally execute a task based on the evaluation of an expression.--- # CONDITIONAL PLAYBOOK
- hosts: demo # Target host group
user: ansible # Running tasks as the 'ansible' user
become: yes # Running with sudo privileges
connection: ssh # Connecting via SSH
tasks:
- name: Install Apache Server for Debian Family
command: apt-get -y install apache2
when: ansible_os_family == "Debian"
- name: Install Apache Server for RedHat Family
command: yum -y install httpd
when: ansible_os_family == "RedHat"
apache2
).httpd
).1️⃣ Continue from the previous LAB (4th Lab)
If you have stopped your instances after the last lab, start all instances and log in via PuTTY.
2️⃣ Log into the Ansible Server