Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
ec04e301
Commit
ec04e301
authored
Jan 14, 2014
by
Richard C Isaacson
Committed by
Michael DeHaan
Jan 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added user option.
parent
3a7e579b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
27 deletions
+43
-27
library/system/at
+43
-27
No files found.
library/system/at
View file @
ec04e301
...
@@ -18,45 +18,50 @@
...
@@ -18,45 +18,50 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION
=
"""
DOCUMENTATION
=
'''
---
---
module: at
module: at
short_description: Schedule the execution of a command or scripts via the at command.
short_description: Schedule the execution of a command or scripts via the at command.
description:
description:
- Use this module to schedule a command or script to run once in the future.
- Use this module to schedule a command or script to run once in the future.
version_added: "0.0"
version_added: "0.0"
options:
options:
command:
user:
description:
description:
- A command to be executed in the future.
- The user to execute the at command as.
required: false
required: false
default: null
default: null
script_file:
command:
description:
description:
- An existing script to be executed in the future.
- A command to be executed in the future.
required: false
required: false
default: null
default: null
unit_count:
script_file:
description:
description:
- The count of units in the future to execute the command or script.
- An existing script to be executed in the future.
required: true
required: false
unit_type:
default: null
description:
unit_count:
- The type of units in the future to execute the command or script.
description:
required: true
- The count of units in the future to execute the command or script.
choices: ["minutes", "hours", "days", "weeks"]
required: true
unit_type:
description:
- The type of units in the future to execute the command or script.
required: true
choices: ["minutes", "hours", "days", "weeks"]
requirements:
requirements:
- at
- at
author: Richard Isaacson
author: Richard Isaacson
"""
'''
EXAMPLES
=
"""
EXAMPLES
=
'''
# Schedule a command to execute in 20 minutes as root.
# Schedule a command to execute in 20 minutes as root.
- at: command="ls -d > /dev/null" unit_count=1 unit_type="minutes"
- at: command="ls -d > /dev/null" unit_count=1 unit_type="minutes"
# Schedule a script to execute in 1 hour as the neo user.
# Schedule a script to execute in 1 hour as the neo user.
- at: script_file="/some/script.sh" user="neo" unit_count=1 unit_type="hours"
- at: script_file="/some/script.sh" user="neo" unit_count=1 unit_type="hours"
"""
'''
import
os
import
os
import
tempfile
import
tempfile
...
@@ -68,6 +73,7 @@ ATCMD = "/usr/bin/at"
...
@@ -68,6 +73,7 @@ ATCMD = "/usr/bin/at"
def
main
():
def
main
():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
user
=
dict
(
required
=
False
),
command
=
dict
(
required
=
False
),
command
=
dict
(
required
=
False
),
script_file
=
dict
(
required
=
False
),
script_file
=
dict
(
required
=
False
),
unit_count
=
dict
(
required
=
True
),
unit_count
=
dict
(
required
=
True
),
...
@@ -79,6 +85,7 @@ def main():
...
@@ -79,6 +85,7 @@ def main():
supports_check_mode
=
False
,
supports_check_mode
=
False
,
)
)
user
=
module
.
params
[
'user'
]
command
=
module
.
params
[
'command'
]
command
=
module
.
params
[
'command'
]
script_file
=
module
.
params
[
'script_file'
]
script_file
=
module
.
params
[
'script_file'
]
unit_count
=
module
.
params
[
'unit_count'
]
unit_count
=
module
.
params
[
'unit_count'
]
...
@@ -98,15 +105,24 @@ def main():
...
@@ -98,15 +105,24 @@ def main():
fileh
=
os
.
fdopen
(
filed
,
'w'
)
fileh
=
os
.
fdopen
(
filed
,
'w'
)
fileh
.
write
(
command
)
fileh
.
write
(
command
)
fileh
.
close
()
fileh
.
close
()
rc
,
out
,
err
=
module
.
run_command
(
"
%
s now +
%
s
%
s -f
%
s"
%
(
ATCMD
,
unit_count
,
unit_type
,
path
))
at_command
=
"
%
s now +
%
s
%
s -f
%
s"
%
(
ATCMD
,
unit_count
,
unit_type
,
path
)
if
user
:
at_command
=
"chown
%
s
%
s; su '
%
s' -c '
%
s'"
%
(
user
,
path
,
user
,
at_command
)
rc
,
out
,
err
=
module
.
run_command
(
at_command
)
if
rc
!=
0
:
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
module
.
fail_json
(
msg
=
err
)
os
.
unlink
(
path
)
os
.
unlink
(
path
)
result
[
'changed'
]
=
'true'
elif
script_file
:
elif
script_file
:
result
[
'script_file'
]
=
script_file
result
[
'script_file'
]
=
script_file
rc
,
out
,
err
=
module
.
run_command
(
"
%
s now +
%
s
%
s -f
%
s"
%
(
ATCMD
,
unit_count
,
unit_type
,
script_file
))
at_command
=
"
%
s now +
%
s
%
s -f
%
s"
%
(
ATCMD
,
unit_count
,
unit_type
,
script_file
)
if
user
:
# We expect that if this is an installed the permissions are already correct for the user to execute it.
at_command
=
"su '
%
s' -c '
%
s'"
%
(
user
,
at_command
)
rc
,
out
,
err
=
module
.
run_command
(
at_command
)
if
rc
!=
0
:
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
module
.
fail_json
(
msg
=
err
)
result
[
'changed'
]
=
'true'
else
:
else
:
module
.
fail_json
(
msg
=
"command or script_file not specified"
)
module
.
fail_json
(
msg
=
"command or script_file not specified"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment