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
bef4c1b9
Commit
bef4c1b9
authored
Aug 07, 2012
by
Matt Wright
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add apt_repository module
parent
454de792
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
library/apt_repository
+71
-0
No files found.
library/apt_repository
0 → 100755
View file @
bef4c1b9
#!/usr/bin/python
import
platform
APT
=
"/usr/bin/apt-get"
ADD_APT_REPOSITORY
=
None
def
_find_binary
():
binaries
=
[
'/usr/bin/add-apt-repository'
]
for
e
in
binaries
:
if
os
.
path
.
exists
(
e
):
return
e
module
.
fail_json
(
msg
=
'Unabled to find any of the following executables '
'
%
s'
%
binaries
)
def
_run
(
cmd
):
# returns (rc, stdout, stderr) from shell command
process
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
stdout
,
stderr
=
process
.
communicate
()
return
(
process
.
returncode
,
stdout
,
stderr
)
def
main
():
arg_spec
=
dict
(
repo
=
dict
(
required
=
True
),
state
=
dict
(
default
=
'present'
,
choices
=
[
'present'
,
'absent'
])
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
global
ADD_APT_REPOSITORY
ADD_APT_REPOSITORY
=
_find_binary
()
repo
=
module
.
params
[
'repo'
]
state
=
module
.
params
[
'state'
]
rc
,
out
,
err
=
_run
(
'
%
s
%
s --remove'
%
(
ADD_APT_REPOSITORY
,
repo
))
existed
=
'Error'
not
in
out
if
state
==
'absent'
:
if
not
existed
:
module
.
exit_json
(
changed
=
False
,
repo
=
repo
)
else
:
module
.
exit_json
(
changed
=
True
,
repo
=
repo
)
cmd
=
'
%
s
%
s'
%
(
ADD_APT_REPOSITORY
,
repo
)
if
float
(
platform
.
dist
()[
1
])
>=
11.10
:
cmd
=
cmd
+
' -y'
rc
,
out
,
err
=
_run
(
cmd
)
changed
=
rc
==
0
and
not
existed
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
if
changed
:
_run
(
'
%
s update'
%
APT
)
module
.
exit_json
(
changed
=
changed
,
existed
=
existed
,
repo
=
repo
,
cmd
=
cmd
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
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