Created
March 30, 2017 08:15
-
-
Save rmn-lux/cfeef675d6770114752cd4aa07cc87c1 to your computer and use it in GitHub Desktop.
Conditionals in Ansible, examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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