うまくいけば、service: allow user to query service status #3316がすぐにコアモジュールにマージされます。
あなたはansible 2.2.0.0を使用して、このdiff to system/service.py
ここにあります私の差分を用いて手でそれをパッチすることができます。私は私のMAC/homebrewのインストールでこれを実行して、それは私のために動作します。 /usr/local/Cellar/ansible/2.2.0.0_2/libexec/lib/python2.7/site-packages/ansible/modules/core/system/service.py
@@ -36,11 +36,12 @@
- Name of the service.
state:
required: false
- choices: [ started, stopped, restarted, reloaded ]
+ choices: [ started, stopped, status, restarted, reloaded ]
description:
- C(started)/C(stopped) are idempotent actions that will not run
- commands unless necessary. C(restarted) will always bounce the
- service. C(reloaded) will always reload. B(At least one of state
+ commands unless necessary. C(status) would report the status of
+ the service C(restarted) will always bounce the service.
+ C(reloaded) will always reload. B(At least one of state
and enabled are required.)
sleep:
required: false
@@ -1455,7 +1456,7 @@
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True),
- state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded']),
+ state = dict(choices=['running', 'started', 'stopped', 'status', 'restarted', 'reloaded']),
sleep = dict(required=False, type='int', default=None),
pattern = dict(required=False, default=None),
enabled = dict(type='bool'),
@@ -1501,6 +1502,9 @@
else:
service.get_service_status()
+ if module.params['state'] == 'status':
+ module.exit_json(state=service.running)
+
# Calculate if request will change service state
service.check_service_changed()
ここhttpdサービスは、それが良い動作します開始:
これは私が編集したファイルです。サービスが停止している場合はエラーが発生します。 – SSN
'service'コマンドがゼロ以外の終了コードで終了する場合は、例えば' failed_when:false'で処理する必要があります。 –