Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

at: PEP8 compliancy and doc fixes #30881

Merged
merged 1 commit into from
Oct 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 38 additions & 52 deletions lib/ansible/modules/system/at.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>

# Copyright: (c) 2014, Richard Isaacson <richard.c.isaacson@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'core'}


DOCUMENTATION = '''
---
module: at
short_description: Schedule the execution of a command or script file via the at command.
short_description: Schedule the execution of a command or script file via the at command
description:
- Use this module to schedule a command or script file to run once in the future.
- All jobs are executed in the 'a' queue.
Expand All @@ -25,56 +23,52 @@
command:
description:
- A command to be executed in the future.
required: false
default: null
script_file:
description:
- An existing script file to be executed in the future.
required: false
default: null
count:
description:
- The count of units in the future to execute the command or script file.
required: true
units:
description:
- The type of units in the future to execute the command or script file.
choices: [ minutes, hours, days, weeks ]
required: true
choices: ["minutes", "hours", "days", "weeks"]
state:
description:
- The state dictates if the command or script file should be evaluated as present(added) or absent(deleted).
required: false
choices: ["present", "absent"]
default: "present"
choices: [ absent, present ]
default: present
unique:
description:
- If a matching job is present a new job will not be added.
required: false
default: false
type: bool
default: 'no'
requirements:
- at
author: "Richard Isaacson (@risaacson)"
author:
- Richard Isaacson (@risaacson)
'''

EXAMPLES = '''
# Schedule a command to execute in 20 minutes as root.
- at:
command: "ls -d / > /dev/null"
- name: Schedule a command to execute in 20 minutes as root.
at:
command: ls -d / >/dev/null
count: 20
units: minutes

# Match a command to an existing job and delete the job.
- at:
command: "ls -d / > /dev/null"
- name: Match a command to an existing job and delete the job.
at:
command: ls -d / >/dev/null
state: absent

# Schedule a command to execute in 20 minutes making sure it is unique in the queue.
- at:
command: "ls -d / > /dev/null"
unique: true
- name: Schedule a command to execute in 20 minutes making sure it is unique in the queue.
at:
command: ls -d / >/dev/null
count: 20
units: minutes
unique: yes
'''

import os
Expand Down Expand Up @@ -140,43 +134,35 @@ def create_tempfile(command):
def main():

module = AnsibleModule(
argument_spec = dict(
command=dict(required=False,
type='str'),
script_file=dict(required=False,
type='str'),
count=dict(required=False,
type='int'),
units=dict(required=False,
default=None,
choices=['minutes', 'hours', 'days', 'weeks'],
type='str'),
state=dict(required=False,
default='present',
choices=['present', 'absent'],
type='str'),
unique=dict(required=False,
default=False,
type='bool')
argument_spec=dict(
command=dict(type='str'),
script_file=dict(type='str'),
count=dict(type='int'),
units=dict(type='str', choices=['minutes', 'hours', 'days', 'weeks']),
state=dict(type='str', default='present', choices=['present', 'absent']),
unique=dict(type='bool', default=False),
),
mutually_exclusive=[['command', 'script_file']],
required_one_of=[['command', 'script_file']],
supports_check_mode=False
supports_check_mode=False,
)

at_cmd = module.get_bin_path('at', True)

command = module.params['command']
script_file = module.params['script_file']
count = module.params['count']
units = module.params['units']
state = module.params['state']
unique = module.params['unique']
command = module.params['command']
script_file = module.params['script_file']
count = module.params['count']
units = module.params['units']
state = module.params['state']
unique = module.params['unique']

if (state == 'present') and (not count or not units):
module.fail_json(msg="present state requires count and units")

result = {'state': state, 'changed': False}
result = dict(
changed=False,
state=state,
)

# If command transform it into a script_file
if command:
Expand Down
1 change: 0 additions & 1 deletion test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py
lib/ansible/modules/storage/netapp/sf_volume_manager.py
lib/ansible/modules/storage/zfs/zfs.py
lib/ansible/modules/system/aix_inittab.py
lib/ansible/modules/system/at.py
lib/ansible/modules/system/capabilities.py
lib/ansible/modules/system/cron.py
lib/ansible/modules/system/cronvar.py
Expand Down