ansible-aix / ansible-power-aix

Developer contributions for Ansible Automation on Power
GNU General Public License v3.0
3 stars 1 forks source link

at review #69

Closed robinvy closed 3 years ago

dberg1 commented 4 years ago

Removing a scheduled job does not work:

fatal: [castor10.coopibm.frec.bull.fr]: FAILED! => {
    "changed": false,
    "cmd": "/usr/bin/at -c root.1599830992c0.a",
    "invocation": {
        "module_args": {
            "command": "ls -d / > /dev/null",
            "count": null,
            "script_file": null,
            "state": "absent",
            "unique": false,
            "units": null
        }
    },
    "msg": "at: syntax error",
    "rc": 1,
    "stderr": "at: syntax error\n",
    "stderr_lines": [
        "at: syntax error"
    ],
    "stdout": "",
    "stdout_lines": []
}

Linux uses "at -c job" to display the job content (including the script). AIX uses "at -lv job".

Linux uses "at -d job" to delete a job. AIX uses "at -r job". Notice that "atrm job" should work on both Linux and AIX.

After changing these two calls, at module works fine for both adding and removing jobs. unique: yes also works with this change (for the same reason).

dberg1 commented 4 years ago

The at module is now in the ansible.posix collection: https://github.com/ansible-collections/ansible.posix/blob/main/plugins/modules/at.py

It looks like AIX is closer to the POSIX standard than Linux: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/at.html POSIX uses -r to remove a job, not -d.

dberg1 commented 4 years ago

I propose the following patch (Linux supports both -r and -d to remove a job):

79a80
> import platform
95c96
<         at_command = "%s -d %s" % (at_cmd, matching_job)
---
>         at_command = "%s -r %s" % (at_cmd, matching_job)
123c124,125
<         at_command = "%s -c %s" % (at_cmd, split_current_job[0])
---
>         at_opt = '-c' if platform.system() != 'AIX' else '-lv'
>         at_command = "%s %s %s" % (at_cmd, at_opt, split_current_job[0])
dberg1 commented 4 years ago

Opened issue https://github.com/ansible-collections/ansible.posix/pull/99

dberg1 commented 4 years ago

PR has been merged upstream.