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
c6b28642
Commit
c6b28642
authored
May 26, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9423 from emonty/features/required-if
Add required_if to AnsibleModule
parents
aea8758b
61ae3c73
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletions
+17
-1
lib/ansible/module_utils/basic.py
+17
-1
No files found.
lib/ansible/module_utils/basic.py
View file @
c6b28642
...
...
@@ -337,7 +337,8 @@ class AnsibleModule(object):
def
__init__
(
self
,
argument_spec
,
bypass_checks
=
False
,
no_log
=
False
,
check_invalid_arguments
=
True
,
mutually_exclusive
=
None
,
required_together
=
None
,
required_one_of
=
None
,
add_file_common_args
=
False
,
supports_check_mode
=
False
):
required_one_of
=
None
,
add_file_common_args
=
False
,
supports_check_mode
=
False
,
required_if
=
None
):
'''
common code for quickly building an ansible module in Python
...
...
@@ -385,6 +386,7 @@ class AnsibleModule(object):
self
.
_check_argument_types
()
self
.
_check_required_together
(
required_together
)
self
.
_check_required_one_of
(
required_one_of
)
self
.
_check_required_if
(
required_if
)
self
.
_set_defaults
(
pre
=
False
)
if
not
self
.
no_log
:
...
...
@@ -958,6 +960,20 @@ class AnsibleModule(object):
if
len
(
missing
)
>
0
:
self
.
fail_json
(
msg
=
"missing required arguments:
%
s"
%
","
.
join
(
missing
))
def
_check_required_if
(
self
,
spec
):
''' ensure that parameters which conditionally required are present '''
if
spec
is
None
:
return
for
(
key
,
val
,
requirements
)
in
spec
:
missing
=
[]
if
key
in
self
.
params
and
self
.
params
[
key
]
==
val
:
for
check
in
requirements
:
count
=
self
.
_count_terms
(
check
)
if
count
==
0
:
missing
.
append
(
check
)
if
len
(
missing
)
>
0
:
self
.
fail_json
(
msg
=
"
%
s is
%
s but the following are missing:
%
s"
%
(
key
,
val
,
','
.
join
(
missing
))
def
_check_argument_values
(
self
):
''' ensure all arguments have the requested values, and there are no stray arguments '''
for
(
k
,
v
)
in
self
.
argument_spec
.
iteritems
():
...
...
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