Last active
October 19, 2023 20:53
-
-
Save tyrells/0a79681de339237cb04c to your computer and use it in GitHub Desktop.
Ansible task to stop service even if it doesn't exist
This file contains hidden or 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
# This task will stop and disable a service without failing if the service does not exist. | |
# Requires Ansible 1.4 or newer. | |
# Update Dec 2016: Have rewritten this for the latest version of ansible and put conditions for both Ubuntu and CentOS | |
- name: "disable unused services" | |
service: name={{item}} state=stopped enabled=no | |
register: command_result | |
failed_when: "unused_disable|failed and ('find' not in unused_disable.msg and 'found' not in unused_disable.msg)" | |
with_items: | |
- httpd | |
- sendmail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A combination of comments here got it working for me: