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
b47bed96
Commit
b47bed96
authored
Jul 25, 2012
by
Nikhil Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standardizing the yum module
parent
8d7f526d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
53 deletions
+17
-53
library/yum
+17
-53
No files found.
library/yum
View file @
b47bed96
...
@@ -19,22 +19,9 @@
...
@@ -19,22 +19,9 @@
#
#
import
os
import
sys
import
yum
import
yum
import
subprocess
import
datetime
import
datetime
import
shlex
import
re
import
traceback
import
traceback
import
syslog
try
:
import
json
except
ImportError
:
import
simplejson
as
json
def
yum_base
(
conf_file
=
None
,
cachedir
=
False
):
def
yum_base
(
conf_file
=
None
,
cachedir
=
False
):
my
=
yum
.
YumBase
()
my
=
yum
.
YumBase
()
...
@@ -289,73 +276,50 @@ def main():
...
@@ -289,73 +276,50 @@ def main():
# list=repos
# list=repos
# list=pkgspec
# list=pkgspec
if
len
(
sys
.
argv
)
==
1
:
module
=
AnsibleModule
(
msg
=
"the yum module requires arguments (-a)"
argument_spec
=
dict
()
return
1
,
msg
)
argfile
=
sys
.
argv
[
1
]
params
=
module
.
params
if
not
os
.
path
.
exists
(
argfile
):
usage
=
"The module expects arguments of the following forms: state=<installed|removed|latest> pkg=<pkgspec> OR list=<installed|updates|available|repos|pkgspec>. pkgspec is nothing but the package specification. Example: google-chrome-stable.i386"
msg
=
"Argument file not found"
return
1
,
msg
args
=
open
(
argfile
,
'r'
)
.
read
()
if
not
len
(
params
):
items
=
shlex
.
split
(
args
)
module
.
fail_json
(
msg
=
usage
)
syslog
.
openlog
(
'ansible-
%
s'
%
os
.
path
.
basename
(
__file__
))
syslog
.
syslog
(
syslog
.
LOG_NOTICE
,
'Invoked with
%
s'
%
args
)
if
not
len
(
items
):
msg
=
"the yum module requires arguments (-a)"
return
1
,
msg
# if nothing else changes - it fails
# if nothing else changes - it fails
results
=
{
'changed'
:
False
,
results
=
{
'changed'
:
False
,
'failed'
:
True
,
'failed'
:
True
,
'results'
:
''
,
'results'
:
''
,
'errors'
:
''
,
'errors'
:
''
,
'msg'
:
args
}
'msg'
:
usage
}
params
=
{}
for
x
in
items
:
try
:
(
k
,
v
)
=
x
.
split
(
"="
,
1
)
except
ValueError
:
msg
=
"invalid arguments:
%
s"
%
args
return
1
,
msg
params
[
k
]
=
v
if
'conf_file'
not
in
params
:
if
'conf_file'
not
in
params
:
params
[
'conf_file'
]
=
None
params
[
'conf_file'
]
=
None
if
'list'
in
params
:
if
'list'
in
params
:
try
:
try
:
my
=
yum_base
(
conf_file
=
params
[
'conf_file'
],
cachedir
=
True
)
my
=
yum_base
(
conf_file
=
params
[
'conf_file'
],
cachedir
=
True
)
results
=
dict
(
results
=
list_stuff
(
my
,
params
[
'list'
]))
results
=
dict
(
results
=
list_stuff
(
my
,
params
[
'list'
]))
except
Exception
,
e
:
except
Exception
,
e
:
return
1
,
str
(
e
)
module
.
fail_json
(
msg
=
str
(
e
)
)
else
:
else
:
pkg
=
params
.
get
(
'pkg'
,
params
.
get
(
'package'
,
params
.
get
(
'name'
,
None
)))
pkg
=
params
.
get
(
'pkg'
,
params
.
get
(
'package'
,
params
.
get
(
'name'
,
None
)))
if
'pkg'
is
None
:
if
'pkg'
is
None
:
results
[
'msg'
]
=
"No pkg specified"
module
.
fail_json
(
msg
=
usage
)
else
:
else
:
try
:
try
:
my
=
yum_base
(
conf_file
=
params
[
'conf_file'
],
cachedir
=
True
)
my
=
yum_base
(
conf_file
=
params
[
'conf_file'
],
cachedir
=
True
)
state
=
params
.
get
(
'state'
,
'installed'
)
state
=
params
.
get
(
'state'
,
'installed'
)
results
=
ensure
(
my
,
state
,
pkg
)
results
=
ensure
(
my
,
state
,
pkg
)
except
Exception
,
e
:
except
Exception
,
e
:
return
1
,
str
(
e
)
module
.
fail_json
(
msg
=
str
(
e
)
)
print
json
.
dumps
(
results
)
module
.
exit_json
(
**
results
)
return
0
,
None
if
__name__
==
"__main__"
:
rc
,
msg
=
main
()
if
rc
!=
0
:
# something went wrong emit the msg
print
json
.
dumps
({
"failed"
:
rc
,
"msg"
:
msg
})
sys
.
exit
(
rc
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
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