Skip to content

Instantly share code, notes, and snippets.

@tgerla
Created November 1, 2013 17:56
Show Gist options
  • Save tgerla/7269228 to your computer and use it in GitHub Desktop.
Save tgerla/7269228 to your computer and use it in GitHub Desktop.
Test to see if selinux is enabled.
---
- hosts: all
tasks:
# this task runs 'getenforce' and registers the result into the "sestatus" variable
# changed_when: false tells ansible never to mark this task as "changed"
- name: test to see if selinux is running
command: getenforce
register: sestatus
changed_when: false
# this task tests to see if the output
- name: print a message if selinux is enabled
debug: msg="selinux is enabled"
when: '"Enabled" in sestatus.stdout'
@truedays
Copy link

truedays commented Nov 1, 2013

On my home machine, getenforce output is "Enforcing"

[ray@f19 ~]$ getenforce
Enforcing
[ray@f19 ~]$ echo $?
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment