2014-02-24 18:08:21 +01:00
|
|
|
# Test code for the script module and action_plugin.
|
2014-02-24 17:57:22 +01:00
|
|
|
# (c) 2014, Richard Isaacson <richard.c.isaacson@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/>.
|
|
|
|
|
|
|
|
##
|
|
|
|
## prep
|
|
|
|
##
|
|
|
|
|
|
|
|
- set_fact: output_dir_test={{output_dir}}/test_script
|
|
|
|
|
|
|
|
- name: make sure our testing sub-directory does not exist
|
|
|
|
file: path="{{ output_dir_test }}" state=absent
|
|
|
|
|
|
|
|
- name: create our testing sub-directory
|
|
|
|
file: path="{{ output_dir_test }}" state=directory
|
|
|
|
|
|
|
|
##
|
|
|
|
## script
|
|
|
|
##
|
|
|
|
|
|
|
|
- name: execute the test.sh script via command
|
|
|
|
script: test.sh
|
|
|
|
register: script_result0
|
|
|
|
|
|
|
|
- name: assert that the script executed correctly
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "script_result0.rc == 0"
|
|
|
|
- "script_result0.stderr == ''"
|
|
|
|
- "script_result0.stdout == 'win'"
|
|
|
|
|
|
|
|
# creates
|
|
|
|
|
|
|
|
- name: verify that afile.txt is absent
|
|
|
|
file: path={{output_dir_test}}/afile.txt state=absent
|
|
|
|
|
|
|
|
- name: create afile.txt with create_afile.sh via command
|
2014-02-24 18:06:22 +01:00
|
|
|
script: create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt
|
2014-02-24 17:57:22 +01:00
|
|
|
|
|
|
|
- name: verify that afile.txt is present
|
|
|
|
file: path={{output_dir_test}}/afile.txt state=file
|
|
|
|
|
|
|
|
# removes
|
|
|
|
|
|
|
|
- name: remove afile.txt with remote_afile.sh via command
|
2014-02-24 18:06:22 +01:00
|
|
|
script: remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt
|
2016-03-31 21:59:19 +02:00
|
|
|
register: script_result1
|
2014-02-24 17:57:22 +01:00
|
|
|
|
|
|
|
- name: verify that afile.txt is absent
|
|
|
|
file: path={{output_dir_test}}/afile.txt state=absent
|
2016-03-31 21:59:19 +02:00
|
|
|
register: script_result2
|
2014-02-24 17:57:22 +01:00
|
|
|
|
|
|
|
- name: assert that the file was removed by the script
|
|
|
|
assert:
|
|
|
|
that:
|
2016-03-19 05:21:55 +01:00
|
|
|
- "script_result1|changed"
|
2016-03-31 21:59:19 +02:00
|
|
|
- "script_result2.state == 'absent'"
|
2017-04-21 07:06:01 +02:00
|
|
|
|
|
|
|
# async
|
|
|
|
- name: test task failure with async param
|
|
|
|
|
|
|
|
script: /some/script.sh
|
|
|
|
async: 2
|
|
|
|
ignore_errors: true
|
|
|
|
register: script_result3
|
|
|
|
|
|
|
|
- name: assert task with async param failed
|
|
|
|
assert:
|
|
|
|
that:
|
2017-04-21 22:17:12 +02:00
|
|
|
- script_result3|failed
|
|
|
|
- script_result3.msg == "async is not supported for this task."
|