2014-02-21 15:00:01 +00:00
|
|
|
# test code for the async keyword
|
|
|
|
# (c) 2014, James Tanner <tanner.jc@gmail.com>
|
|
|
|
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
- name: run a 2 second loop
|
|
|
|
shell: for i in $(seq 1 2); do echo $i ; sleep 1; done;
|
|
|
|
async: 10
|
|
|
|
poll: 1
|
|
|
|
register: async_result
|
|
|
|
|
|
|
|
|
|
|
|
- debug: var=async_result
|
|
|
|
|
|
|
|
- name: validate async returns
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'ansible_job_id' in async_result"
|
|
|
|
- "'changed' in async_result"
|
|
|
|
- "'cmd' in async_result"
|
|
|
|
- "'delta' in async_result"
|
|
|
|
- "'end' in async_result"
|
2016-07-07 18:40:58 +00:00
|
|
|
- "'finished' in async_result or async_result.finished == 1"
|
2014-02-21 15:00:01 +00:00
|
|
|
- "'rc' in async_result"
|
|
|
|
- "'start' in async_result"
|
|
|
|
- "'stderr' in async_result"
|
|
|
|
- "'stdout' in async_result"
|
|
|
|
- "'stdout_lines' in async_result"
|
|
|
|
- "async_result.rc == 0"
|
|
|
|
|
2014-03-26 20:48:42 +00:00
|
|
|
- name: test async without polling
|
|
|
|
command: sleep 5
|
|
|
|
async: 30
|
|
|
|
poll: 0
|
|
|
|
register: async_result
|
|
|
|
|
|
|
|
- debug: var=async_result
|
|
|
|
|
|
|
|
- name: validate async without polling returns
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'ansible_job_id' in async_result"
|
|
|
|
- "'started' in async_result"
|
2016-07-07 18:40:58 +00:00
|
|
|
- "'finished' not in async_result or async_result.finished == 0"
|
2014-07-12 17:30:05 +00:00
|
|
|
|
|
|
|
- name: test skipped task handling
|
2016-04-18 14:47:38 +00:00
|
|
|
command: /bin/true
|
2014-07-12 17:30:05 +00:00
|
|
|
async: 15
|
|
|
|
poll: 0
|
|
|
|
when: False
|
2014-09-25 20:42:45 +00:00
|
|
|
|
|
|
|
# test async "fire and forget, but check later"
|
|
|
|
|
|
|
|
- name: 'start a task with "fire-and-forget"'
|
2016-05-31 21:47:36 +00:00
|
|
|
command: sleep 3
|
2014-09-25 20:42:45 +00:00
|
|
|
async: 30
|
|
|
|
poll: 0
|
|
|
|
register: fnf_task
|
|
|
|
|
|
|
|
- name: assert task was successfully started
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- fnf_task.started
|
|
|
|
- "'ansible_job_id' in fnf_task"
|
|
|
|
|
|
|
|
- name: 'check on task started as a "fire-and-forget"'
|
|
|
|
async_status: jid={{ fnf_task.ansible_job_id }}
|
|
|
|
register: fnf_result
|
|
|
|
until: fnf_result.finished
|
2016-05-31 21:47:36 +00:00
|
|
|
retries: 10
|
|
|
|
delay: 1
|
2014-09-25 20:42:45 +00:00
|
|
|
|
|
|
|
- name: assert task was successfully checked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- fnf_result.finished
|
2016-10-02 15:03:42 +00:00
|
|
|
|
|
|
|
- name: test graceful module failure
|
|
|
|
async_test:
|
|
|
|
fail_mode: graceful
|
|
|
|
async: 30
|
|
|
|
poll: 1
|
|
|
|
register: async_result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: assert task failed correctly
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- async_result.ansible_job_id is match('\d+\.\d+')
|
|
|
|
- async_result.finished == 1
|
|
|
|
- async_result | changed == false
|
|
|
|
- async_result | failed
|
|
|
|
- async_result.msg == 'failed gracefully'
|
|
|
|
|
|
|
|
- name: test exception module failure
|
|
|
|
async_test:
|
|
|
|
fail_mode: exception
|
|
|
|
async: 5
|
|
|
|
poll: 1
|
|
|
|
register: async_result
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: validate response
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- async_result.ansible_job_id is match('\d+\.\d+')
|
|
|
|
- async_result.finished == 1
|
|
|
|
- async_result.changed == false
|
|
|
|
- async_result | failed == true
|
|
|
|
- async_result.stderr is search('failing via exception', multiline=True)
|
|
|
|
|
|
|
|
- name: test leading junk before JSON
|
|
|
|
async_test:
|
|
|
|
fail_mode: leading_junk
|
|
|
|
async: 5
|
|
|
|
poll: 1
|
|
|
|
register: async_result
|
|
|
|
|
|
|
|
- name: validate response
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- async_result.ansible_job_id is match('\d+\.\d+')
|
|
|
|
- async_result.finished == 1
|
|
|
|
- async_result.changed == true
|
|
|
|
- async_result | success
|
|
|
|
|
|
|
|
- name: test trailing junk after JSON
|
|
|
|
async_test:
|
|
|
|
fail_mode: trailing_junk
|
|
|
|
async: 5
|
|
|
|
poll: 1
|
|
|
|
register: async_result
|
|
|
|
|
|
|
|
- name: validate response
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- async_result.ansible_job_id is match('\d+\.\d+')
|
|
|
|
- async_result.finished == 1
|
|
|
|
- async_result.changed == true
|
|
|
|
- async_result | success
|
|
|
|
- async_result.warnings[0] is search('trailing junk after module output')
|