Переглянути джерело

Use ansible systemd module to check service status

Kenjiro Nakayama 6 роки тому
батько
коміт
ee6546cd59

+ 8 - 7
playbooks/common/openshift-cluster/upgrades/init.yml

@@ -24,14 +24,15 @@
   - name: set currently installed version
     set_fact:
       openshift_currently_installed_version: "{{ openshift_master_installed_version }}"
-  - name: Check if iptables is running
-    command: systemctl status iptables
-    changed_when: false
-    failed_when: false
-    register: service_iptables_status
-    check_mode: no
+
+  - name: Get iptable service details
+    systemd:
+      name: "iptables"
+    ignore_errors: true
+    register: iptables_service
 
   - name: Set fact os_firewall_use_firewalld FALSE for iptables
     set_fact:
       os_firewall_use_firewalld: false
-    when: service_iptables_status.rc != 0
+    when:
+    - iptables_service.status.ActiveState != 'active'

+ 4 - 5
roles/contiv_facts/tasks/rpm.yml

@@ -7,16 +7,15 @@
   check_mode: no
 
 - name: RPM | Determine if firewalld enabled
-  command: "systemctl status firewalld.service"
+  systemd:
+    name: "firewalld"
+  ignore_errors: true
   register: ss
-  changed_when: false
-  failed_when: false
-  check_mode: no
 
 - name: Set the contiv_has_firewalld fact
   set_fact:
     contiv_has_firewalld: true
-  when: s.rc == 0 and ss.rc == 0
+  when: s.rc == 0 and ss.status.ActiveState == 'active'
 
 - name: Determine if iptables-services installed
   command: "rpm -q iptables-services"