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
1cae0a68
Commit
1cae0a68
authored
11 years ago
by
Gabe Mulley
Committed by
Michael DeHaan
11 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a module for update-alternatives
parent
aaaf9dbc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
137 additions
and
0 deletions
+137
-0
library/system/alternatives
+137
-0
No files found.
library/system/alternatives
0 → 100755
View file @
1cae0a68
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ansible module to manage symbolic link alternatives.
(c) 2014, Gabe Mulley <gabe.mulley@gmail.com>
This file is part of Ansible
Ansible is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ansible is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
DOCUMENTATION
=
'''
---
module: alternatives
short_description: Manages symbolic links
description:
- Manages symbolic links using the 'update-alternatives' tool provided on debian-like systems.
- Useful when multiple programs are installed but provide similar functionality (e.g. different editors).
version_added: "1.5"
options:
name:
description:
- The generic name of the link.
required: true
path:
description:
- The path to the real executable that the link should point to.
required: true
link:
description:
- The path to the symbolic link that should point to the real executable.
required: false
requirements: [ update-alternatives ]
'''
EXAMPLES
=
'''
- name: correct java version selected
alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
- name: alternatives link created
alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible
'''
UPDATE_ALTERNATIVES
=
'/usr/sbin/update-alternatives'
DEFAULT_LINK_PRIORITY
=
50
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
name
=
dict
(
required
=
True
),
path
=
dict
(
required
=
True
),
link
=
dict
(
required
=
False
),
)
)
params
=
module
.
params
name
=
params
[
'name'
]
path
=
params
[
'path'
]
link
=
params
[
'link'
]
current_path
=
None
all_alternatives
=
[]
(
rc
,
query_output
,
query_error
)
=
module
.
run_command
(
[
UPDATE_ALTERNATIVES
,
'--query'
,
name
]
)
# Gather the current setting and all alternatives from the query output.
# Query output should look something like this:
# Name: java
# Link: /usr/bin/java
# Slaves:
# java.1.gz /usr/share/man/man1/java.1.gz
# Status: manual
# Best: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
# Value: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
# Alternative: /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java
# Priority: 1061
# Slaves:
# java.1.gz /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
# Alternative: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
# Priority: 1071
# Slaves:
# java.1.gz /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
if
rc
==
0
:
for
line
in
query_output
.
splitlines
():
split_line
=
line
.
split
(
':'
)
if
len
(
split_line
)
==
2
:
key
=
split_line
[
0
]
value
=
split_line
[
1
]
.
strip
()
if
key
==
'Value'
:
current_path
=
value
elif
key
==
'Alternative'
:
all_alternatives
.
append
(
value
)
if
current_path
!=
path
:
try
:
# install the requested path if necessary
if
path
not
in
all_alternatives
:
module
.
run_command
(
[
UPDATE_ALTERNATIVES
,
'--install'
,
link
,
name
,
path
,
str
(
DEFAULT_LINK_PRIORITY
)],
check_rc
=
True
)
# select the requested path
module
.
run_command
(
[
UPDATE_ALTERNATIVES
,
'--set'
,
name
,
path
],
check_rc
=
True
)
module
.
exit_json
(
changed
=
True
)
except
subprocess
.
CalledProcessError
as
cpe
:
module
.
fail_json
(
msg
=
str
(
dir
(
cpe
)))
else
:
module
.
exit_json
(
changed
=
False
)
# import module snippets
from
ansible.module_utils.basic
import
*
main
()
This diff is collapsed.
Click to expand it.
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