PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/test/integration/roles/test_win_service/tasks/main.yml

https://github.com/ajanthanm/ansible
YAML | 196 lines | 147 code | 33 blank | 16 comment | 0 complexity | f38ae71d5720204b3a0931300a526306 MD5 | raw file
  1# test code for the win_service module
  2# (c) 2014, Chris Church <chris@ninemoreminutes.com>
  3
  4# This file is part of Ansible
  5#
  6# Ansible is free software: you can redistribute it and/or modify
  7# it under the terms of the GNU General Public License as published by
  8# the Free Software Foundation, either version 3 of the License, or
  9# (at your option) any later version.
 10#
 11# Ansible is distributed in the hope that it will be useful,
 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14# GNU General Public License for more details.
 15#
 16# You should have received a copy of the GNU General Public License
 17# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
 18
 19- name: test win_service module with short name
 20  win_service: name="{{ test_win_service_name }}"
 21  register: win_service_name
 22
 23- name: check win_service result with short name
 24  assert:
 25    that:
 26      - "not win_service_name|changed"
 27      - "win_service_name.name"
 28      - "win_service_name.display_name"
 29      - "win_service_name.start_mode"
 30      - "win_service_name.state"
 31
 32- name: test win_service module with display name
 33  win_service: name="{{ test_win_service_display_name }}"
 34  register: win_service_display_name
 35
 36- name: check win_service result with display name
 37  assert:
 38    that:
 39      - "not win_service_display_name|changed"
 40      - "win_service_display_name.name"
 41      - "win_service_display_name.display_name"
 42      - "win_service_display_name.start_mode"
 43      - "win_service_display_name.state"
 44
 45- name: test win_service module with invalid name
 46  win_service: name="iamnotaservice"
 47  ignore_errors: true
 48  register: win_service_invalid
 49
 50- name: check win_service result with invalid_name
 51  assert:
 52    that:
 53      - "win_service_invalid|failed"
 54      - "win_service_invalid.msg"
 55
 56- name: make sure the service is stopped and disabled
 57  win_service: name="{{ test_win_service_name }}" state=stopped start_mode=disabled
 58  register: win_service_stopped_disabled
 59
 60- name: check result of disabling and stopping the service
 61  assert:
 62    that:
 63      - "win_service_stopped_disabled.start_mode == 'disabled'"
 64      - "win_service_stopped_disabled.state == 'stopped'"
 65
 66- name: try to start the disabled service
 67  win_service: name="{{ test_win_service_name }}" state=started
 68  register: win_service_start_disabled
 69  ignore_errors: true
 70
 71- name: check that starting the disabled service fails
 72  assert:
 73    that:
 74      - "win_service_start_disabled|failed"
 75      - "win_service_start_disabled.msg"
 76
 77- name: enable the service for manual startup
 78  win_service: name="{{ test_win_service_name }}" start_mode=manual
 79  register: win_service_manual_start_mode
 80
 81- name: check that enabling the service succeeds for manual startup
 82  assert:
 83    that:
 84      - "win_service_manual_start_mode|changed"
 85      - "win_service_manual_start_mode.start_mode == 'manual'"
 86      - "win_service_manual_start_mode.state == 'stopped'"
 87
 88- name: enable the service again for manual startup
 89  win_service: name="{{ test_win_service_name }}" start_mode=manual
 90  register: win_service_manual_start_mode_again
 91
 92- name: check that enabling the service succeeds for manual startup
 93  assert:
 94    that:
 95      - "not win_service_manual_start_mode_again|changed"
 96      - "win_service_manual_start_mode_again.start_mode == 'manual'"
 97      - "win_service_manual_start_mode_again.state == 'stopped'"
 98
 99- name: try to start the manual service
100  win_service: name="{{ test_win_service_name }}" state=started
101  register: win_service_start_manual
102
103- name: check that starting the manual service succeeds
104  assert:
105    that:
106      - "win_service_start_manual|changed"
107      - "win_service_start_manual.start_mode == 'manual'"
108      - "win_service_start_manual.state == 'running'"
109
110- name: try to start the manual service again
111  win_service: name="{{ test_win_service_name }}" state=started
112  register: win_service_start_manual_again
113
114- name: check that starting the manual service again succeeds without changes
115  assert:
116    that:
117      - "not win_service_start_manual_again|changed"
118      - "win_service_start_manual_again.start_mode == 'manual'"
119      - "win_service_start_manual_again.state == 'running'"
120
121- name: enable the service for automatic startup
122  win_service: name="{{ test_win_service_name }}" start_mode=auto
123  register: win_service_auto_start_mode
124
125- name: check that enabling the service succeeds for automatic startup
126  assert:
127    that:
128      - "win_service_auto_start_mode|changed"
129      - "win_service_auto_start_mode.start_mode == 'auto'"
130      - "win_service_auto_start_mode.state == 'running'"
131
132- name: enable the service again for automatic startup
133  win_service: name="{{ test_win_service_name }}" start_mode=auto
134  register: win_service_auto_start_mode_again
135
136- name: check that enabling the service succeeds for automatic startup without changes
137  assert:
138    that:
139      - "not win_service_auto_start_mode_again|changed"
140      - "win_service_auto_start_mode_again.start_mode == 'auto'"
141      - "win_service_auto_start_mode_again.state == 'running'"
142
143- name: restart the service
144  win_service: name="{{ test_win_service_name }}" state=restarted
145  register: win_service_restart_auto
146
147- name: check that restarting the service succeeds with changes
148  assert:
149    that:
150      - "win_service_restart_auto|changed"
151      - "win_service_restart_auto.start_mode == 'auto'"
152      - "win_service_restart_auto.state == 'running'"
153
154- name: disable the service again
155  win_service: name="{{ test_win_service_name }}" start_mode=disabled
156  register: win_service_disabled_start_mode
157
158- name: check that disabling the service succeeds, service is still running
159  assert:
160    that:
161      - "win_service_disabled_start_mode|changed"
162      - "win_service_disabled_start_mode.start_mode == 'disabled'"
163      - "win_service_disabled_start_mode.state == 'running'"
164
165- name: disable the service again
166  win_service: name="{{ test_win_service_name }}" start_mode=disabled
167  register: win_service_disabled_start_mode_again
168
169- name: check that disabling the service succeeds again
170  assert:
171    that:
172      - "not win_service_disabled_start_mode_again|changed"
173      - "win_service_disabled_start_mode_again.start_mode == 'disabled'"
174      - "win_service_disabled_start_mode_again.state == 'running'"
175
176- name: stop the service
177  win_service: name="{{ test_win_service_name }}" state=stopped
178  register: win_service_stop_disabled
179
180- name: check that stopping the service succeeds with changes
181  assert:
182    that:
183      - "win_service_stop_disabled|changed"
184      - "win_service_stop_disabled.start_mode == 'disabled'"
185      - "win_service_stop_disabled.state == 'stopped'"
186
187- name: stop the service again
188  win_service: name="{{ test_win_service_name }}" state=stopped
189  register: win_service_stop_disabled_again
190
191- name: check that stopping the service again succeeds without changes
192  assert:
193    that:
194      - "not win_service_stop_disabled_again|changed"
195      - "win_service_stop_disabled_again.start_mode == 'disabled'"
196      - "win_service_stop_disabled_again.state == 'stopped'"