diff --git a/lib/ansible/runner/action_plugins/script.py b/lib/ansible/runner/action_plugins/script.py index 6b584c15b6..149be3cc11 100644 --- a/lib/ansible/runner/action_plugins/script.py +++ b/lib/ansible/runner/action_plugins/script.py @@ -16,6 +16,7 @@ # along with Ansible. If not, see . import os +import re import shlex import ansible.constants as C @@ -24,8 +25,8 @@ from ansible import utils from ansible import errors from ansible.runner.return_data import ReturnData -class ActionModule(object): +class ActionModule(object): TRANSFERS_FILES = True def __init__(self, runner): @@ -36,35 +37,85 @@ class ActionModule(object): if self.runner.noop_on_check(inject): # in check mode, always skip this module - return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for this module')) + return ReturnData(conn=conn, comm_ok=True, + result=dict(skipped=True, msg='check mode not supported for this module')) + + # extract ansible reserved parameters + # From library/command keep in sync + creates = None + removes = None + r = re.compile(r'(^|\s)(creates|removes)=(?P[\'"])?(.*?)(?(quote)(? "$1" \ No newline at end of file diff --git a/test/integration/roles/test_script/files/remove_afile.sh b/test/integration/roles/test_script/files/remove_afile.sh new file mode 100755 index 0000000000..4a7fea6617 --- /dev/null +++ b/test/integration/roles/test_script/files/remove_afile.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +rm "$1" \ No newline at end of file diff --git a/test/integration/roles/test_script/files/test.sh b/test/integration/roles/test_script/files/test.sh new file mode 100755 index 0000000000..ade17e9b8c --- /dev/null +++ b/test/integration/roles/test_script/files/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo -n "win" \ No newline at end of file diff --git a/test/integration/roles/test_script/meta/main.yml b/test/integration/roles/test_script/meta/main.yml new file mode 100644 index 0000000000..1050c23ce3 --- /dev/null +++ b/test/integration/roles/test_script/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - prepare_tests + diff --git a/test/integration/roles/test_script/tasks/main.yml b/test/integration/roles/test_script/tasks/main.yml new file mode 100644 index 0000000000..ffbe40d600 --- /dev/null +++ b/test/integration/roles/test_script/tasks/main.yml @@ -0,0 +1,69 @@ +# Test code for the script module and action_plugin. +# (c) 2014, Richard Isaacson + +# 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 . + +## +## 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 + script: create_afile.sh {{output_dir_test | expanduser}}/afile.txt creates={{output_dir_test | expanduser}}/afile.txt + +- 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 + script: remove_afile.sh {{output_dir_test | expanduser}}/afile.txt removes={{output_dir_test | expanduser}}/afile.txt + +- name: verify that afile.txt is absent + file: path={{output_dir_test}}/afile.txt state=absent + register: script_result1 + +- name: assert that the file was removed by the script + assert: + that: + - "script_result1.changed != True"