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
d9d59708
Commit
d9d59708
authored
Mar 01, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2222 from sfromm/issue2114
Update various modules for check_mode
parents
f5ba0c61
8f0d8a85
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
58 additions
and
9 deletions
+58
-9
library/apt_key
+5
-0
library/apt_repository
+5
-1
library/easy_install
+5
-1
library/pip
+5
-0
library/seboolean
+4
-1
library/selinux
+10
-1
library/slurp
+2
-1
library/subversion
+6
-1
library/supervisorctl
+9
-1
library/svr4pkg
+7
-2
No files found.
library/apt_key
View file @
d9d59708
...
@@ -130,6 +130,7 @@ def main():
...
@@ -130,6 +130,7 @@ def main():
key
=
dict
(
required
=
False
),
key
=
dict
(
required
=
False
),
state
=
dict
(
required
=
False
,
choices
=
[
'present'
,
'absent'
],
default
=
'present'
)
state
=
dict
(
required
=
False
,
choices
=
[
'present'
,
'absent'
],
default
=
'present'
)
),
),
supports_check_mode
=
True
)
)
key_id
=
module
.
params
[
'id'
]
key_id
=
module
.
params
[
'id'
]
...
@@ -153,6 +154,8 @@ def main():
...
@@ -153,6 +154,8 @@ def main():
if
key_id
and
key_id
in
keys
:
if
key_id
and
key_id
in
keys
:
module
.
exit_json
(
changed
=
False
)
module
.
exit_json
(
changed
=
False
)
else
:
else
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
add_key
(
module
,
data
)
add_key
(
module
,
data
)
changed
=
False
changed
=
False
keys2
=
all_keys
(
module
)
keys2
=
all_keys
(
module
)
...
@@ -165,6 +168,8 @@ def main():
...
@@ -165,6 +168,8 @@ def main():
if
not
key_id
:
if
not
key_id
:
module
.
fail_json
(
msg
=
"key is required"
)
module
.
fail_json
(
msg
=
"key is required"
)
if
key_id
in
keys
:
if
key_id
in
keys
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
if
remove_key
(
module
,
key_id
):
if
remove_key
(
module
,
key_id
):
changed
=
True
changed
=
True
else
:
else
:
...
...
library/apt_repository
View file @
d9d59708
...
@@ -90,7 +90,7 @@ def main():
...
@@ -90,7 +90,7 @@ def main():
state
=
dict
(
default
=
'present'
,
choices
=
[
'present'
,
'absent'
])
state
=
dict
(
default
=
'present'
,
choices
=
[
'present'
,
'absent'
])
)
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
,
supports_check_mode
=
True
)
if
not
HAVE_PYAPT
:
if
not
HAVE_PYAPT
:
module
.
fail_json
(
msg
=
"Could not import python modules: apt, apt_pkg. Please install python-apt package."
)
module
.
fail_json
(
msg
=
"Could not import python modules: apt, apt_pkg. Please install python-apt package."
)
...
@@ -119,9 +119,13 @@ def main():
...
@@ -119,9 +119,13 @@ def main():
out
=
''
out
=
''
err
=
''
err
=
''
if
state
==
'absent'
and
exists
:
if
state
==
'absent'
and
exists
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
cmd
=
'
%
s "
%
s" --remove'
%
(
add_apt_repository
,
repo
)
cmd
=
'
%
s "
%
s" --remove'
%
(
add_apt_repository
,
repo
)
rc
,
out
,
err
=
module
.
run_command
(
cmd
)
rc
,
out
,
err
=
module
.
run_command
(
cmd
)
elif
state
==
'present'
and
not
exists
:
elif
state
==
'present'
and
not
exists
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
cmd
=
'
%
s "
%
s"'
%
(
add_apt_repository
,
repo
)
cmd
=
'
%
s "
%
s"'
%
(
add_apt_repository
,
repo
)
rc
,
out
,
err
=
module
.
run_command
(
cmd
)
rc
,
out
,
err
=
module
.
run_command
(
cmd
)
else
:
else
:
...
...
library/easy_install
View file @
d9d59708
...
@@ -86,7 +86,7 @@ def main():
...
@@ -86,7 +86,7 @@ def main():
virtualenv_command
=
dict
(
default
=
'virtualenv'
,
required
=
False
),
virtualenv_command
=
dict
(
default
=
'virtualenv'
,
required
=
False
),
)
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
,
supports_check_mode
=
True
)
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
env
=
module
.
params
[
'virtualenv'
]
env
=
module
.
params
[
'virtualenv'
]
...
@@ -102,6 +102,8 @@ def main():
...
@@ -102,6 +102,8 @@ def main():
virtualenv
=
module
.
get_bin_path
(
virtualenv_command
,
True
)
virtualenv
=
module
.
get_bin_path
(
virtualenv_command
,
True
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
command
=
'
%
s
%
s'
%
(
virtualenv
,
env
)
command
=
'
%
s
%
s'
%
(
virtualenv
,
env
)
if
site_packages
:
if
site_packages
:
command
+=
' --system-site-packages'
command
+=
' --system-site-packages'
...
@@ -116,6 +118,8 @@ def main():
...
@@ -116,6 +118,8 @@ def main():
installed
=
_is_package_installed
(
module
,
name
,
easy_install
)
installed
=
_is_package_installed
(
module
,
name
,
easy_install
)
if
not
installed
:
if
not
installed
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
cmd
=
'
%
s
%
s'
%
(
easy_install
,
name
)
cmd
=
'
%
s
%
s'
%
(
easy_install
,
name
)
rc_pip
,
out_pip
,
err_pip
=
module
.
run_command
(
cmd
)
rc_pip
,
out_pip
,
err_pip
=
module
.
run_command
(
cmd
)
...
...
library/pip
View file @
d9d59708
...
@@ -165,6 +165,7 @@ def main():
...
@@ -165,6 +165,7 @@ def main():
),
),
required_one_of
=
[[
'name'
,
'requirements'
]],
required_one_of
=
[[
'name'
,
'requirements'
]],
mutually_exclusive
=
[[
'name'
,
'requirements'
]],
mutually_exclusive
=
[[
'name'
,
'requirements'
]],
supports_check_mode
=
True
)
)
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
...
@@ -188,6 +189,8 @@ def main():
...
@@ -188,6 +189,8 @@ def main():
if
env
:
if
env
:
virtualenv
=
module
.
get_bin_path
(
virtualenv_command
,
True
)
virtualenv
=
module
.
get_bin_path
(
virtualenv_command
,
True
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
if
module
.
params
[
'virtualenv_site_packages'
]:
if
module
.
params
[
'virtualenv_site_packages'
]:
cmd
=
'
%
s --system-site-packages
%
s'
%
(
virtualenv
,
env
)
cmd
=
'
%
s --system-site-packages
%
s'
%
(
virtualenv
,
env
)
else
:
else
:
...
@@ -210,6 +213,8 @@ def main():
...
@@ -210,6 +213,8 @@ def main():
elif
requirements
:
elif
requirements
:
cmd
+=
' -r
%
s'
%
requirements
cmd
+=
' -r
%
s'
%
requirements
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
rc
,
out_pip
,
err_pip
=
module
.
run_command
(
cmd
)
rc
,
out_pip
,
err_pip
=
module
.
run_command
(
cmd
)
out
+=
out_pip
out
+=
out_pip
err
+=
err_pip
err
+=
err_pip
...
...
library/seboolean
View file @
d9d59708
...
@@ -160,7 +160,8 @@ def main():
...
@@ -160,7 +160,8 @@ def main():
name
=
dict
(
required
=
True
),
name
=
dict
(
required
=
True
),
persistent
=
dict
(
default
=
'no'
,
type
=
'bool'
),
persistent
=
dict
(
default
=
'no'
,
type
=
'bool'
),
state
=
dict
(
required
=
True
,
type
=
'bool'
)
state
=
dict
(
required
=
True
,
type
=
'bool'
)
)
),
supports_check_mode
=
True
)
)
if
not
HAVE_SELINUX
:
if
not
HAVE_SELINUX
:
...
@@ -188,6 +189,8 @@ def main():
...
@@ -188,6 +189,8 @@ def main():
result
[
'changed'
]
=
False
result
[
'changed'
]
=
False
module
.
exit_json
(
**
result
)
module
.
exit_json
(
**
result
)
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
if
persistent
:
if
persistent
:
r
=
semanage_boolean_value
(
module
,
name
,
state
)
r
=
semanage_boolean_value
(
module
,
name
,
state
)
else
:
else
:
...
...
library/selinux
View file @
d9d59708
...
@@ -124,7 +124,8 @@ def main():
...
@@ -124,7 +124,8 @@ def main():
policy
=
dict
(
required
=
False
),
policy
=
dict
(
required
=
False
),
state
=
dict
(
choices
=
[
'enforcing'
,
'permissive'
,
'disabled'
],
required
=
True
),
state
=
dict
(
choices
=
[
'enforcing'
,
'permissive'
,
'disabled'
],
required
=
True
),
configfile
=
dict
(
aliases
=
[
'conf'
,
'file'
],
default
=
'/etc/selinux/config'
)
configfile
=
dict
(
aliases
=
[
'conf'
,
'file'
],
default
=
'/etc/selinux/config'
)
)
),
supports_check_mode
=
True
)
)
# global vars
# global vars
...
@@ -155,16 +156,22 @@ def main():
...
@@ -155,16 +156,22 @@ def main():
# check changed values and run changes
# check changed values and run changes
if
(
policy
!=
runtime_policy
):
if
(
policy
!=
runtime_policy
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
# cannot change runtime policy
# cannot change runtime policy
msgs
.
append
(
'reboot to change the loaded policy'
)
msgs
.
append
(
'reboot to change the loaded policy'
)
changed
=
True
changed
=
True
if
(
policy
!=
config_policy
):
if
(
policy
!=
config_policy
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
msgs
.
append
(
'config policy changed from
\'
%
s
\'
to
\'
%
s
\'
'
%
(
config_policy
,
policy
))
msgs
.
append
(
'config policy changed from
\'
%
s
\'
to
\'
%
s
\'
'
%
(
config_policy
,
policy
))
set_config_policy
(
policy
,
configfile
)
set_config_policy
(
policy
,
configfile
)
changed
=
True
changed
=
True
if
(
state
!=
runtime_state
):
if
(
state
!=
runtime_state
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
if
(
state
==
'disabled'
):
if
(
state
==
'disabled'
):
msgs
.
append
(
'state change will take effect next reboot'
)
msgs
.
append
(
'state change will take effect next reboot'
)
else
:
else
:
...
@@ -176,6 +183,8 @@ def main():
...
@@ -176,6 +183,8 @@ def main():
changed
=
True
changed
=
True
if
(
state
!=
config_state
):
if
(
state
!=
config_state
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
msgs
.
append
(
'config state changed from
\'
%
s
\'
to
\'
%
s
\'
'
%
(
config_state
,
state
))
msgs
.
append
(
'config state changed from
\'
%
s
\'
to
\'
%
s
\'
'
%
(
config_state
,
state
))
set_config_state
(
state
,
configfile
)
set_config_state
(
state
,
configfile
)
changed
=
True
changed
=
True
...
...
library/slurp
View file @
d9d59708
...
@@ -51,7 +51,8 @@ def main():
...
@@ -51,7 +51,8 @@ def main():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
src
=
dict
(
required
=
True
,
aliases
=
[
'path'
]),
src
=
dict
(
required
=
True
,
aliases
=
[
'path'
]),
)
),
supports_check_mode
=
True
)
)
source
=
module
.
params
[
'src'
]
source
=
module
.
params
[
'src'
]
...
...
library/subversion
View file @
d9d59708
...
@@ -132,7 +132,8 @@ def main():
...
@@ -132,7 +132,8 @@ def main():
force
=
dict
(
default
=
'yes'
,
type
=
'bool'
),
force
=
dict
(
default
=
'yes'
,
type
=
'bool'
),
username
=
dict
(
required
=
False
),
username
=
dict
(
required
=
False
),
password
=
dict
(
required
=
False
),
password
=
dict
(
required
=
False
),
)
),
supports_check_mode
=
True
)
)
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
...
@@ -147,11 +148,15 @@ def main():
...
@@ -147,11 +148,15 @@ def main():
if
not
os
.
path
.
exists
(
dest
):
if
not
os
.
path
.
exists
(
dest
):
before
=
None
before
=
None
local_mods
=
False
local_mods
=
False
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
svn
.
checkout
()
svn
.
checkout
()
elif
os
.
path
.
exists
(
"
%
s/.svn"
%
(
dest
,
)):
elif
os
.
path
.
exists
(
"
%
s/.svn"
%
(
dest
,
)):
# Order matters. Need to get local mods before switch to avoid false
# Order matters. Need to get local mods before switch to avoid false
# positives. Need to switch before revert to ensure we are reverting to
# positives. Need to switch before revert to ensure we are reverting to
# correct repo.
# correct repo.
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
before
=
svn
.
get_revision
()
before
=
svn
.
get_revision
()
local_mods
=
svn
.
has_local_mods
()
local_mods
=
svn
.
has_local_mods
()
svn
.
switch
()
svn
.
switch
()
...
...
library/supervisorctl
View file @
d9d59708
...
@@ -51,7 +51,7 @@ def main():
...
@@ -51,7 +51,7 @@ def main():
state
=
dict
(
required
=
True
,
choices
=
[
'present'
,
'started'
,
'restarted'
,
'stopped'
])
state
=
dict
(
required
=
True
,
choices
=
[
'present'
,
'started'
,
'restarted'
,
'stopped'
])
)
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
,
supports_check_mode
=
True
)
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
...
@@ -63,6 +63,8 @@ def main():
...
@@ -63,6 +63,8 @@ def main():
if
state
==
'present'
:
if
state
==
'present'
:
if
not
present
:
if
not
present
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
module
.
run_command
(
'
%
s reread'
%
SUPERVISORCTL
,
check_rc
=
True
)
module
.
run_command
(
'
%
s reread'
%
SUPERVISORCTL
,
check_rc
=
True
)
rc
,
out
,
err
=
module
.
run_command
(
'
%
s add
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s add
%
s'
%
(
SUPERVISORCTL
,
name
))
...
@@ -80,6 +82,8 @@ def main():
...
@@ -80,6 +82,8 @@ def main():
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
if
running
and
state
==
'stopped'
:
if
running
and
state
==
'stopped'
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
rc
,
out
,
err
=
module
.
run_command
(
'
%
s stop
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s stop
%
s'
%
(
SUPERVISORCTL
,
name
))
if
'
%
s: stopped'
%
name
in
out
:
if
'
%
s: stopped'
%
name
in
out
:
...
@@ -88,6 +92,8 @@ def main():
...
@@ -88,6 +92,8 @@ def main():
module
.
fail_json
(
msg
=
out
)
module
.
fail_json
(
msg
=
out
)
elif
state
==
'restarted'
:
elif
state
==
'restarted'
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
rc
,
out
,
err
=
module
.
run_command
(
'
%
s update
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s update
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s restart
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s restart
%
s'
%
(
SUPERVISORCTL
,
name
))
...
@@ -97,6 +103,8 @@ def main():
...
@@ -97,6 +103,8 @@ def main():
module
.
fail_json
(
msg
=
out
)
module
.
fail_json
(
msg
=
out
)
elif
not
running
and
state
==
'started'
:
elif
not
running
and
state
==
'started'
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
rc
,
out
,
err
=
module
.
run_command
(
'
%
s start
%
s'
%
(
SUPERVISORCTL
,
name
))
rc
,
out
,
err
=
module
.
run_command
(
'
%
s start
%
s'
%
(
SUPERVISORCTL
,
name
))
if
'
%
s: started'
%
name
in
out
:
if
'
%
s: started'
%
name
in
out
:
...
...
library/svr4pkg
View file @
d9d59708
...
@@ -128,8 +128,9 @@ def main():
...
@@ -128,8 +128,9 @@ def main():
state
=
dict
(
required
=
True
,
choices
=
[
'present'
,
'absent'
]),
state
=
dict
(
required
=
True
,
choices
=
[
'present'
,
'absent'
]),
src
=
dict
(
default
=
None
),
src
=
dict
(
default
=
None
),
proxy
=
dict
(
default
=
None
)
proxy
=
dict
(
default
=
None
)
)
),
)
supports_check_mode
=
True
)
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
src
=
module
.
params
[
'src'
]
src
=
module
.
params
[
'src'
]
...
@@ -146,6 +147,8 @@ def main():
...
@@ -146,6 +147,8 @@ def main():
module
.
fail_json
(
name
=
name
,
module
.
fail_json
(
name
=
name
,
msg
=
"src is required when state=present"
)
msg
=
"src is required when state=present"
)
if
not
package_installed
(
module
,
name
):
if
not
package_installed
(
module
,
name
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
(
rc
,
out
,
err
)
=
package_install
(
module
,
name
,
src
,
proxy
)
(
rc
,
out
,
err
)
=
package_install
(
module
,
name
,
src
,
proxy
)
# Stdout is normally empty but for some packages can be
# Stdout is normally empty but for some packages can be
# very long and is not often useful
# very long and is not often useful
...
@@ -154,6 +157,8 @@ def main():
...
@@ -154,6 +157,8 @@ def main():
elif
state
==
'absent'
:
elif
state
==
'absent'
:
if
package_installed
(
module
,
name
):
if
package_installed
(
module
,
name
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
(
rc
,
out
,
err
)
=
package_uninstall
(
module
,
name
,
src
)
(
rc
,
out
,
err
)
=
package_uninstall
(
module
,
name
,
src
)
out
=
out
[:
75
]
out
=
out
[:
75
]
...
...
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