From 17f8c023616c9cb52c0cf836a8c91aedcf81e292 Mon Sep 17 00:00:00 2001 From: Baptiste Mille-Mathias Date: Sun, 30 May 2021 18:18:57 +0200 Subject: [PATCH] Update changelogs/fragments/102_module_at_add_chdir_option.yml Co-authored-by: quidame --- .../102_module_at_add_chdir_option.yml | 2 +- plugins/modules/at.py | 7 +++--- tests/integration/targets/at/tasks/main.yml | 23 ++++++++++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/changelogs/fragments/102_module_at_add_chdir_option.yml b/changelogs/fragments/102_module_at_add_chdir_option.yml index 4e67a9e..e4724ed 100644 --- a/changelogs/fragments/102_module_at_add_chdir_option.yml +++ b/changelogs/fragments/102_module_at_add_chdir_option.yml @@ -1,2 +1,2 @@ minor_changes: - - module at - add option ``chdir`` to permit to launch the at command from a specific directory (https://github.com/ansible-collections/ansible.posix/pull/102). + - at - add option ``chdir`` to permit to launch the ``at`` command from a specific directory (https://github.com/ansible-collections/ansible.posix/issues/13). diff --git a/plugins/modules/at.py b/plugins/modules/at.py index 75dfcec..97213c6 100644 --- a/plugins/modules/at.py +++ b/plugins/modules/at.py @@ -19,8 +19,8 @@ version_added: "1.0.0" options: chdir: description: - - An optional location from where to run the command C(at). Useful for intance - when running a playbook using ansible-pull with C(purge) option. + - An optional location from where to run the command C(at). + - Useful for intance when running a playbook using ansible-pull with C(purge) option. type: path version_added: 1.3.0 command: @@ -194,8 +194,7 @@ def main(): result['count'] = count result['units'] = units - add_job(module, result, at_cmd, count, units, command, script_file, - chdir=chdir) + add_job(module, result, at_cmd, count, units, command, script_file, chdir=chdir) module.exit_json(**result) diff --git a/tests/integration/targets/at/tasks/main.yml b/tests/integration/targets/at/tasks/main.yml index 1cd3f1d..3351532 100644 --- a/tests/integration/targets/at/tasks/main.yml +++ b/tests/integration/targets/at/tasks/main.yml @@ -61,7 +61,7 @@ - 'at_test0.state is defined' - 'at_test0.units is defined' -- name: add a at useless command +- name: Add a useless command using at at: command: /bin/logger 'AT task ran from Ansible' count: 1 @@ -71,11 +71,11 @@ - debug: var=at_add -- name: pause, giving the time the at runs once +- name: Wait for at to run the previous command pause: minutes: 1 -- name: add a at useless command +- name: Add a useless command at: command: /bin/logger 'AT task ran from Ansible' count: 1 @@ -83,11 +83,16 @@ unique: true state: absent register: at_removal - ignore_errors: true - debug: var=at_removal -- name: create an at command with chdir with valid value +- name: Validate results + assert: + that: + - at_add is changed + - at_removal is changed + +- name: Create an at command with chdir with valid value at: command: /bin/logger 'AT task ran from Ansible with chdir' count: 1 @@ -96,7 +101,7 @@ register: at_chdir_valid - debug: var=at_chdir_valid -- name: create an at command with chdir with invalid value +- name: Create an at command with chdir with invalid value at: command: /bin/logger 'AT task ran from Ansible with chdir' count: 1 @@ -106,3 +111,9 @@ ignore_errors: true - debug: var=at_chdir_invalid + +- name: Validate results + assert: + that: + - at_chdir_valid is changed + - not at_chdir_valid is changed