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
917c11eb
Commit
917c11eb
authored
Mar 17, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2355 from jcftang/macports
Teach the macports module to activate/deactivate packages
parents
4ee08aaf
32bf6050
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
3 deletions
+68
-3
library/macports
+68
-3
No files found.
library/macports
View file @
917c11eb
...
...
@@ -34,7 +34,7 @@ options:
state:
description:
- state of the package
choices: [ 'present', 'absent' ]
choices: [ 'present', 'absent'
, 'active', 'inactive'
]
required: false
default: present
update_cache:
...
...
@@ -49,7 +49,8 @@ EXAMPLES = '''
macports: name=foo state=present
macports: name=foo state=present update_cache=yes
macports: name=foo state=absent
macports: name=foo,bar state=absent
macports: name=foo state=active
macports: name=foo state=inactive
'''
...
...
@@ -73,6 +74,14 @@ def query_package(module, port_path, name, state="present"):
return
False
elif
state
==
"active"
:
rc
,
out
,
err
=
module
.
run_command
(
"
%
s installed
%
s | grep -q active"
%
(
port_path
,
name
))
if
rc
==
0
:
return
True
return
False
def
remove_packages
(
module
,
port_path
,
packages
):
""" Uninstalls one or more packages if installed. """
...
...
@@ -120,11 +129,61 @@ def install_packages(module, port_path, packages):
module
.
exit_json
(
changed
=
False
,
msg
=
"package(s) already present"
)
def
activate_packages
(
module
,
port_path
,
packages
):
""" Activate a package if it's inactive. """
activate_c
=
0
for
package
in
packages
:
if
not
query_package
(
module
,
port_path
,
package
):
module
.
fail_json
(
msg
=
"failed to activate
%
s, package(s) not present"
%
(
package
))
if
query_package
(
module
,
port_path
,
package
,
state
=
"active"
):
continue
rc
,
out
,
err
=
module
.
run_command
(
"
%
s activate
%
s"
%
(
port_path
,
package
))
if
not
query_package
(
module
,
port_path
,
package
,
state
=
"active"
):
module
.
fail_json
(
msg
=
"failed to activate
%
s:
%
s"
%
(
package
,
out
))
activate_c
+=
1
if
activate_c
>
0
:
module
.
exit_json
(
changed
=
True
,
msg
=
"activated
%
s package(s)"
%
(
activate_c
))
module
.
exit_json
(
changed
=
False
,
msg
=
"package(s) already active"
)
def
deactivate_packages
(
module
,
port_path
,
packages
):
""" Deactivate a package if it's active. """
deactivated_c
=
0
for
package
in
packages
:
if
not
query_package
(
module
,
port_path
,
package
):
module
.
fail_json
(
msg
=
"failed to activate
%
s, package(s) not present"
%
(
package
))
if
not
query_package
(
module
,
port_path
,
package
,
state
=
"active"
):
continue
rc
,
out
,
err
=
module
.
run_command
(
"
%
s deactivate
%
s"
%
(
port_path
,
package
))
if
query_package
(
module
,
port_path
,
package
,
state
=
"active"
):
module
.
fail_json
(
msg
=
"failed to deactivated
%
s:
%
s"
%
(
package
,
out
))
deactivated_c
+=
1
if
deactivated_c
>
0
:
module
.
exit_json
(
changed
=
True
,
msg
=
"deactivated
%
s package(s)"
%
(
deactivated_c
))
module
.
exit_json
(
changed
=
False
,
msg
=
"package(s) already inactive"
)
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
name
=
dict
(
aliases
=
[
"pkg"
],
required
=
True
),
state
=
dict
(
default
=
"present"
,
choices
=
[
"present"
,
"installed"
,
"absent"
,
"removed"
]),
state
=
dict
(
default
=
"present"
,
choices
=
[
"present"
,
"installed"
,
"absent"
,
"removed"
,
"active"
,
"inactive"
]),
update_cache
=
dict
(
default
=
"no"
,
aliases
=
[
"update-cache"
],
type
=
'bool'
)
)
)
...
...
@@ -144,6 +203,12 @@ def main():
elif
p
[
"state"
]
in
[
"absent"
,
"removed"
]:
remove_packages
(
module
,
port_path
,
pkgs
)
elif
p
[
"state"
]
==
"active"
:
activate_packages
(
module
,
port_path
,
pkgs
)
elif
p
[
"state"
]
==
"inactive"
:
deactivate_packages
(
module
,
port_path
,
pkgs
)
# 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