diff --git a/changelogs/fragments/pc_fixes.yml b/changelogs/fragments/pc_fixes.yml new file mode 100644 index 00000000000000..951c34a23dd8fa --- /dev/null +++ b/changelogs/fragments/pc_fixes.yml @@ -0,0 +1,2 @@ +bugfixes: + - moved assemble, raw, copy, fetch, reboot, script and wait_for_connection to query task instead of play_context ensuring they get the lastest and most correct data. diff --git a/lib/ansible/plugins/action/assemble.py b/lib/ansible/plugins/action/assemble.py index 7998de041aa8a3..6d0634c48578e9 100644 --- a/lib/ansible/plugins/action/assemble.py +++ b/lib/ansible/plugins/action/assemble.py @@ -139,7 +139,7 @@ def run(self, tmp=None, task_vars=None): if path_checksum != dest_stat['checksum']: - if self._play_context.diff: + if self._task.diff: diff = self._get_diff_data(dest, path, task_vars) remote_path = self._connection._shell.join_path(self._connection._shell.tmpdir, 'src') diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py index b0b1dc643f9eb6..a735dfb5477579 100644 --- a/lib/ansible/plugins/action/copy.py +++ b/lib/ansible/plugins/action/copy.py @@ -210,7 +210,7 @@ def _ensure_invocation(self, result): # NOTE: do not add to this. This should be made a generic function for action plugins. # This should also use the same argspec as the module instead of keeping it in sync. if 'invocation' not in result: - if self._play_context.no_log: + if self._task.no_log: result['invocation'] = "CENSORED: no_log is set" else: # NOTE: Should be removed in the future. For now keep this broken @@ -283,10 +283,10 @@ def _copy_file(self, source_full, source_rel, content, content_tempfile, if local_checksum != dest_status['checksum']: # The checksums don't match and we will change or error out. - if self._play_context.diff and not raw: + if self._task.diff and not raw: result['diff'].append(self._get_diff_data(dest_file, source_full, task_vars, content)) - if self._play_context.check_mode: + if self._task.check_mode: self._remove_tempfile_if_content_defined(content, content_tempfile) result['changed'] = True return result diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py index d89ff264b74661..4c62382ba7d892 100644 --- a/lib/ansible/plugins/action/fetch.py +++ b/lib/ansible/plugins/action/fetch.py @@ -41,7 +41,7 @@ def run(self, tmp=None, task_vars=None): del tmp # tmp no longer has any effect try: - if self._play_context.check_mode: + if self._task.check_mode: raise AnsibleActionSkip('check mode not (yet) supported for this module') source = self._task.args.get('src', None) diff --git a/lib/ansible/plugins/action/raw.py b/lib/ansible/plugins/action/raw.py index 7b4d461e7504db..ac337c00778feb 100644 --- a/lib/ansible/plugins/action/raw.py +++ b/lib/ansible/plugins/action/raw.py @@ -32,7 +32,7 @@ def run(self, tmp=None, task_vars=None): result = super(ActionModule, self).run(tmp, task_vars) del tmp # tmp no longer has any effect - if self._play_context.check_mode: + if self._task.check_mode: # in --check mode, always skip this module execution result['skipped'] = True return result diff --git a/lib/ansible/plugins/action/reboot.py b/lib/ansible/plugins/action/reboot.py index e3a4267759d03a..f92f84065851fa 100644 --- a/lib/ansible/plugins/action/reboot.py +++ b/lib/ansible/plugins/action/reboot.py @@ -414,7 +414,7 @@ def run(self, tmp=None, task_vars=None): msg = 'Running {0} with local connection would reboot the control node.'.format(self._task.action) return {'changed': False, 'elapsed': 0, 'rebooted': False, 'failed': True, 'msg': msg} - if self._play_context.check_mode: + if self._task.check_mode: return {'changed': True, 'elapsed': 0, 'rebooted': True} if task_vars is None: diff --git a/lib/ansible/plugins/action/script.py b/lib/ansible/plugins/action/script.py index 494002c4be8511..783041633488d2 100644 --- a/lib/ansible/plugins/action/script.py +++ b/lib/ansible/plugins/action/script.py @@ -150,11 +150,11 @@ def run(self, tmp=None, task_vars=None): # like become and environment args if getattr(self._connection._shell, "_IS_WINDOWS", False): # FUTURE: use a more public method to get the exec payload - pc = self._play_context + pc = self._task exec_data = ps_manifest._create_powershell_wrapper( to_bytes(script_cmd), source, {}, env_dict, self._task.async_val, pc.become, pc.become_method, pc.become_user, - pc.become_pass, pc.become_flags, "script", task_vars, None + self._play_context.become_pass, pc.become_flags, "script", task_vars, None ) # build the necessary exec wrapper command # FUTURE: this still doesn't let script work on Windows with non-pipelined connections or diff --git a/lib/ansible/plugins/action/wait_for_connection.py b/lib/ansible/plugins/action/wait_for_connection.py index 533f93cb5d3df1..9eb3fac975ecf5 100644 --- a/lib/ansible/plugins/action/wait_for_connection.py +++ b/lib/ansible/plugins/action/wait_for_connection.py @@ -68,7 +68,7 @@ def run(self, tmp=None, task_vars=None): sleep = int(self._task.args.get('sleep', self.DEFAULT_SLEEP)) timeout = int(self._task.args.get('timeout', self.DEFAULT_TIMEOUT)) - if self._play_context.check_mode: + if self._task.check_mode: display.vvv("wait_for_connection: skipping for check_mode") return dict(skipped=True) diff --git a/test/units/plugins/action/test_raw.py b/test/units/plugins/action/test_raw.py index ebbfdfcac765b5..68cdb231a2f9fb 100644 --- a/test/units/plugins/action/test_raw.py +++ b/test/units/plugins/action/test_raw.py @@ -36,6 +36,20 @@ def setUp(self): def tearDown(self): pass + def _build_task(self, params=None): + + task = MagicMock(Task) + task.async_val = False + task.diff = False + task.check_mode = False + task.environment = None + + if params is None: + task.args = {'_raw_params': 'Args1'} + else: + task.args = params + + return task # The current behavior of the raw aciton in regards to executable is currently in question; # the test_raw_executable_is_not_empty_string verifies the current behavior (whether it is desireed or not. # Please refer to the following for context: @@ -44,11 +58,7 @@ def tearDown(self): def test_raw_executable_is_not_empty_string(self): - task = MagicMock(Task) - task.async_val = False - - task.args = {'_raw_params': 'Args1'} - self.play_context.check_mode = False + task = self._build_task() self.mock_am = ActionModule(task, self.connection, self.play_context, loader=None, templar=None, shared_loader_obj=None) self.mock_am._low_level_execute_command = Mock(return_value={}) @@ -60,22 +70,14 @@ def test_raw_executable_is_not_empty_string(self): def test_raw_check_mode_is_True(self): - task = MagicMock(Task) - task.async_val = False - - task.args = {'_raw_params': 'Args1'} - self.play_context.check_mode = True + task = self._build_task() + task.check_mode = True self.mock_am = ActionModule(task, self.connection, self.play_context, loader=None, templar=None, shared_loader_obj=None) def test_raw_test_environment_is_None(self): - task = MagicMock(Task) - task.async_val = False - - task.args = {'_raw_params': 'Args1'} - task.environment = None - self.play_context.check_mode = False + task = self._build_task() self.mock_am = ActionModule(task, self.connection, self.play_context, loader=None, templar=None, shared_loader_obj=None) self.mock_am._low_level_execute_command = Mock(return_value={}) @@ -85,12 +87,7 @@ def test_raw_test_environment_is_None(self): def test_raw_task_vars_is_not_None(self): - task = MagicMock(Task) - task.async_val = False - - task.args = {'_raw_params': 'Args1'} - task.environment = None - self.play_context.check_mode = False + task = self._build_task() self.mock_am = ActionModule(task, self.connection, self.play_context, loader=None, templar=None, shared_loader_obj=None) self.mock_am._low_level_execute_command = Mock(return_value={}) diff --git a/test/units/plugins/action/test_reboot.py b/test/units/plugins/action/test_reboot.py index 07e2694c5ebe5c..ba03f3e259b614 100644 --- a/test/units/plugins/action/test_reboot.py +++ b/test/units/plugins/action/test_reboot.py @@ -26,6 +26,8 @@ def module_task(mocker, task_args): task.action = 'reboot' task.args = task_args task.async_val = False + task.check_mode = False + task.diff = False return task