Skip to content

Instantly share code, notes, and snippets.

@rmn-lux
Created March 30, 2017 08:15
Show Gist options
  • Save rmn-lux/cfeef675d6770114752cd4aa07cc87c1 to your computer and use it in GitHub Desktop.
Save rmn-lux/cfeef675d6770114752cd4aa07cc87c1 to your computer and use it in GitHub Desktop.
Conditionals in Ansible, examples
---
- hosts: test
tasks:
- name: Check OS family
debug: msg="This is my OS"
when: ansible_os_family == "Debian"
- name: Check if Apache2 is installed
command: dpkg-query -W apache2
register: apache2_check
- name: Print message if apache installed
debug: msg="Apache2 is installed on remote host"
when: "'apache2' in apache2_check.stdout"
- name: Check if admin logged
command: who
register: who_check
- name: Print message if user admin not logged
debug: msg="User admin is not logged on remote host"
when: not 'admin' in who_check.stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment