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
21a35bde
Commit
21a35bde
authored
Jul 30, 2012
by
Seth Vidal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new patch - adds a 'boolean' function to the module_common class and cleans up
the apt module to use it
parent
c4c53d54
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
7 deletions
+20
-7
lib/ansible/module_common.py
+16
-0
library/apt
+4
-7
No files found.
lib/ansible/module_common.py
View file @
21a35bde
...
...
@@ -23,6 +23,9 @@ MODULE_COMMON = """
# == BEGIN DYNAMICALLY INSERTED CODE ==
MODULE_ARGS = "<<INCLUDE_ANSIBLE_MODULE_ARGS>>"
BOOLEANS_TRUE = ['yes', 'on', '1', 'true', 1]
BOOLEANS_FALSE = ['no', 'off', '0', 'false', 0]
BOOLEANS = BOOLEANS_TRUE + BOOLEANS_FALSE
# ansible modules can be written in any language. To simplify
# development of Python modules, the functions available here
...
...
@@ -42,6 +45,7 @@ import shlex
import subprocess
import sys
import syslog
import types
try:
from hashlib import md5 as _md5
...
...
@@ -128,6 +132,18 @@ class AnsibleModule(object):
log_args = re.sub(r'password=.+ (.*)', r"password=NOT_LOGGING_PASSWORD
\1
", self.args)
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with
%
s'
%
log_args)
def boolean(self, arg):
''' return a bool for the arg '''
if type(arg) in types.StringTypes:
arg = arg.lower()
if arg in BOOLEANS_TRUE:
return True
elif arg in BOOLEANS_FALSE:
return False
else:
self.fail_json(msg='Boolean
%
s not in either boolean list'
%
arg)
def jsonify(self, data):
return json.dumps(data)
...
...
library/apt
View file @
21a35bde
...
...
@@ -130,7 +130,7 @@ def main():
if
p
[
'package'
]
is
None
and
p
[
'update_cache'
]
!= 'yes':
module
.
fail_json
(
msg
=
'pkg=name and/or update-cache=yes is required'
)
install_recommends
=
(
p
[
'install_recommends'
]
==
'yes'
)
install_recommends
=
module
.
boolean
(
p
[
'install_recommends'
]
)
cache
=
apt
.
Cache
()
if
p
[
'default_release'
]:
...
...
@@ -138,16 +138,13 @@ def main():
#
reopen
cache
w
/
modified
config
cache
.
open
(
progress
=
None
)
if
p
[
'update_cache'
]
==
'yes'
:
if
modules
.
boolean
(
p
[
'update_cache'
])
cache
.
update
()
cache
.
open
(
progress
=
None
)
if
p
[
'package'
]
==
None
:
module
.
exit_json
(
changed
=
False
)
if
p
[
'force'
]
==
'yes'
:
force_yes
=
True
else
:
force_yes
=
False
force_yes
=
modules
.
boolean
(
p
[
'force'
])
if
p
[
'package'
].
count
(
'='
)
>
1
:
module
.
fail_json
(
msg
=
'invalid package spec'
)
...
...
@@ -164,7 +161,7 @@ def main():
install
(
module
,
p
[
'package'
],
cache
,
default_release
=
p
[
'default_release'
],
install_recommends
=
install_recommends
,
force
=
force_yes
)
elif
p
[
'state'
]
==
'removed'
:
remove
(
module
,
p
[
'package'
],
cache
,
purge
=
p
[
'purge'
]
)
remove
(
module
,
p
[
'package'
],
cache
,
purge
=
modules
.
boolean
(
p
[
'purge'
])
)
#
this
is
magic
,
see
lib
/
ansible
/
module_common
.
py
#<<
INCLUDE_ANSIBLE_MODULE_COMMON
>>
...
...
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