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
b0ac7e07
Commit
b0ac7e07
authored
Aug 30, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'binpath' of
https://github.com/sfromm/ansible
into devel
Conflicts: library/supervisorctl
parents
a454db53
6742e9c3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
102 deletions
+53
-102
lib/ansible/module_common.py
+28
-0
library/apt_repository
+2
-12
library/easy_install
+6
-14
library/group
+3
-11
library/pip
+2
-28
library/service
+1
-4
library/setup
+4
-10
library/supervisorctl
+4
-12
library/user
+3
-11
No files found.
lib/ansible/module_common.py
View file @
b0ac7e07
...
@@ -202,6 +202,34 @@ class AnsibleModule(object):
...
@@ -202,6 +202,34 @@ class AnsibleModule(object):
log_args = re.sub(r'login_password=.+ (.*)', r"login_password=NOT_LOGGING_PASSWORD
\1
", log_args)
log_args = re.sub(r'login_password=.+ (.*)', r"login_password=NOT_LOGGING_PASSWORD
\1
", log_args)
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with
%
s'
%
log_args)
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with
%
s'
%
log_args)
def get_bin_path(self, arg, required=False, opt_dirs=[]):
'''
find system executable in PATH.
Optional arguments:
- required: if executable is not found and required is true, fail_json
- opt_dirs: optional list of directories to search in addition to PATH
if found return full path; otherwise return None
'''
sbin_paths = ['/sbin', '/usr/sbin', '/usr/local/sbin']
paths = []
for d in opt_dirs:
if d is not None and os.path.exists(d):
paths.append(d)
paths += os.environ.get('PATH').split(':')
bin_path = None
# mangle PATH to include /sbin dirs
for p in sbin_paths:
if p not in paths and os.path.exists(p):
paths.append(p)
for d in paths:
path = os.path.join(d, arg)
if os.path.exists(path) and os.access(path, os.X_OK):
bin_path = path
break
if required and bin_path is None:
self.fail_json(msg='Failed to find required executable
%
s'
%
arg)
return bin_path
def boolean(self, arg):
def boolean(self, arg):
''' return a bool for the arg '''
''' return a bool for the arg '''
if arg is None or type(arg) == bool:
if arg is None or type(arg) == bool:
...
...
library/apt_repository
View file @
b0ac7e07
...
@@ -26,17 +26,7 @@
...
@@ -26,17 +26,7 @@
import
platform
import
platform
APT
=
"/usr/bin/apt-get"
APT
=
"/usr/bin/apt-get"
ADD_APT_REPO
=
'add-apt-repository'
def
_find_binary
(
module
):
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
):
def
_run
(
cmd
):
if
platform
.
dist
()[
0
]
==
'debian'
or
float
(
platform
.
dist
()[
1
])
>=
11.10
:
if
platform
.
dist
()[
0
]
==
'debian'
or
float
(
platform
.
dist
()[
1
])
>=
11.10
:
...
@@ -58,7 +48,7 @@ def main():
...
@@ -58,7 +48,7 @@ def main():
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
module
=
AnsibleModule
(
argument_spec
=
arg_spec
)
add_apt_repository
=
_find_binary
(
modul
e
)
add_apt_repository
=
module
.
get_bin_path
(
ADD_APT_REPO
,
Tru
e
)
repo
=
module
.
params
[
'repo'
]
repo
=
module
.
params
[
'repo'
]
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
...
...
library/easy_install
View file @
b0ac7e07
...
@@ -19,18 +19,6 @@
...
@@ -19,18 +19,6 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
#
def
_find_easy_install
(
env
):
if
env
:
return
os
.
path
.
join
(
env
,
'bin'
,
'easy_install'
)
paths
=
[
'/usr/local/bin'
,
'/usr/bin'
]
for
p
in
paths
:
e
=
p
+
'/easy_install'
if
os
.
path
.
exists
(
e
):
return
e
def
_ensure_virtualenv
(
env
,
virtualenv
):
def
_ensure_virtualenv
(
env
,
virtualenv
):
if
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
return
0
,
''
,
''
return
0
,
''
,
''
...
@@ -62,14 +50,18 @@ def main():
...
@@ -62,14 +50,18 @@ def main():
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
env
=
module
.
params
[
'virtualenv'
]
env
=
module
.
params
[
'virtualenv'
]
easy_install
=
_find_easy_install
(
env
)
easy_install
=
module
.
get_bin_path
(
'easy_install'
,
True
,
[
'
%
s/bin'
%
env
]
)
rc
=
0
rc
=
0
err
=
''
err
=
''
out
=
''
out
=
''
if
env
:
if
env
:
rc_venv
,
out_venv
,
err_venv
=
_ensure_virtualenv
(
env
,
'/usr/local/bin/virtualenv'
)
virtualenv
=
module
.
get_bin_path
(
'virtualenv'
,
True
)
if
virtualenv
is
None
:
module
.
fail_json
(
msg
=
'virtualenv is not installed'
)
rc_venv
,
out_venv
,
err_venv
=
_ensure_virtualenv
(
env
,
virtualenv
)
rc
+=
rc_venv
rc
+=
rc_venv
out
+=
out_venv
out
+=
out_venv
...
...
library/group
View file @
b0ac7e07
...
@@ -20,23 +20,15 @@
...
@@ -20,23 +20,15 @@
import
grp
import
grp
def
get_bin_path
(
module
,
arg
):
if
os
.
path
.
exists
(
'/usr/sbin/
%
s'
%
arg
):
return
'/usr/sbin/
%
s'
%
arg
elif
os
.
path
.
exists
(
'/sbin/
%
s'
%
arg
):
return
'/sbin/
%
s'
%
arg
else
:
module
.
fail_json
(
msg
=
"Cannot find
%
s"
%
arg
)
def
group_del
(
module
,
group
):
def
group_del
(
module
,
group
):
cmd
=
[
get_bin_path
(
module
,
'groupdel'
),
group
]
cmd
=
[
module
.
get_bin_path
(
'groupdel'
,
True
),
group
]
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
p
.
communicate
()
(
out
,
err
)
=
p
.
communicate
()
rc
=
p
.
returncode
rc
=
p
.
returncode
return
(
rc
,
out
,
err
)
return
(
rc
,
out
,
err
)
def
group_add
(
module
,
group
,
**
kwargs
):
def
group_add
(
module
,
group
,
**
kwargs
):
cmd
=
[
get_bin_path
(
module
,
'groupadd'
)]
cmd
=
[
module
.
get_bin_path
(
'groupadd'
,
True
)]
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
==
'gid'
and
kwargs
[
key
]
is
not
None
:
if
key
==
'gid'
and
kwargs
[
key
]
is
not
None
:
cmd
.
append
(
'-g'
)
cmd
.
append
(
'-g'
)
...
@@ -50,7 +42,7 @@ def group_add(module, group, **kwargs):
...
@@ -50,7 +42,7 @@ def group_add(module, group, **kwargs):
return
(
rc
,
out
,
err
)
return
(
rc
,
out
,
err
)
def
group_mod
(
module
,
group
,
**
kwargs
):
def
group_mod
(
module
,
group
,
**
kwargs
):
cmd
=
[
get_bin_path
(
module
,
'groupmod'
)]
cmd
=
[
module
.
get_bin_path
(
'groupmod'
,
True
)]
info
=
group_info
(
group
)
info
=
group_info
(
group
)
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
==
'gid'
:
if
key
==
'gid'
:
...
...
library/pip
View file @
b0ac7e07
...
@@ -27,32 +27,6 @@ def _get_full_name(name, version=None):
...
@@ -27,32 +27,6 @@ def _get_full_name(name, version=None):
resp
=
name
+
'=='
+
version
resp
=
name
+
'=='
+
version
return
resp
return
resp
def
_find_pip
(
module
,
env
):
paths
=
[
'/usr/local/bin'
,
'/usr/bin'
]
if
env
:
paths
=
[
os
.
path
.
join
(
env
,
'bin'
)]
+
paths
for
p
in
paths
:
pe
=
p
+
'/pip'
if
os
.
path
.
exists
(
pe
):
return
pe
module
.
fail_json
(
msg
=
'pip is not installed'
)
def
_find_virtualenv
(
module
):
paths
=
[
'/usr/local/bin'
,
'/usr/bin'
]
for
p
in
paths
:
ve
=
p
+
'/virtualenv'
if
os
.
path
.
exists
(
ve
):
return
ve
module
.
fail_json
(
msg
=
'virtualenv is not installed'
)
def
_ensure_virtualenv
(
module
,
env
,
virtualenv
):
def
_ensure_virtualenv
(
module
,
env
,
virtualenv
):
if
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
if
os
.
path
.
exists
(
os
.
path
.
join
(
env
,
'bin'
,
'activate'
)):
return
0
,
''
,
''
return
0
,
''
,
''
...
@@ -103,7 +77,7 @@ def main():
...
@@ -103,7 +77,7 @@ def main():
env
=
module
.
params
[
'virtualenv'
]
env
=
module
.
params
[
'virtualenv'
]
if
env
:
if
env
:
virtualenv
=
_find_virtualenv
(
modul
e
)
virtualenv
=
module
.
get_bin_path
(
'virtualenv'
,
Tru
e
)
rc_venv
,
out_venv
,
err_venv
=
_ensure_virtualenv
(
module
,
env
,
virtualenv
)
rc_venv
,
out_venv
,
err_venv
=
_ensure_virtualenv
(
module
,
env
,
virtualenv
)
...
@@ -111,7 +85,7 @@ def main():
...
@@ -111,7 +85,7 @@ def main():
out
+=
out_venv
out
+=
out_venv
err
+=
err_venv
err
+=
err_venv
pip
=
_find_pip
(
module
,
env
)
pip
=
module
.
get_bin_path
(
'pip'
,
True
,
[
'
%
s/bin'
%
env
]
)
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
...
...
library/service
View file @
b0ac7e07
...
@@ -39,10 +39,7 @@ def _find_binaries(m):
...
@@ -39,10 +39,7 @@ def _find_binaries(m):
location
[
binary
]
=
None
location
[
binary
]
=
None
for
binary
in
binaries
:
for
binary
in
binaries
:
for
path
in
paths
:
location
[
binary
]
=
m
.
get_bin_path
(
binary
)
if
os
.
path
.
exists
(
path
+
'/'
+
binary
):
location
[
binary
]
=
path
+
'/'
+
binary
break
if
location
.
get
(
'systemctl'
,
None
):
if
location
.
get
(
'systemctl'
,
None
):
CHKCONFIG
=
location
[
'systemctl'
]
CHKCONFIG
=
location
[
'systemctl'
]
...
...
library/setup
View file @
b0ac7e07
...
@@ -436,7 +436,9 @@ class LinuxNetwork(Network):
...
@@ -436,7 +436,9 @@ class LinuxNetwork(Network):
Network
.
__init__
(
self
)
Network
.
__init__
(
self
)
def
populate
(
self
):
def
populate
(
self
):
ip_path
=
self
.
get_ip_path
()
ip_path
=
module
.
get_bin_path
(
'ip'
)
if
ip_path
is
None
:
return
self
.
facts
default_ipv4
,
default_ipv6
=
self
.
get_default_interfaces
(
ip_path
)
default_ipv4
,
default_ipv6
=
self
.
get_default_interfaces
(
ip_path
)
interfaces
,
ips
=
self
.
get_interfaces_info
(
ip_path
,
default_ipv4
,
default_ipv6
)
interfaces
,
ips
=
self
.
get_interfaces_info
(
ip_path
,
default_ipv4
,
default_ipv6
)
self
.
facts
[
'interfaces'
]
=
interfaces
.
keys
()
self
.
facts
[
'interfaces'
]
=
interfaces
.
keys
()
...
@@ -448,15 +450,6 @@ class LinuxNetwork(Network):
...
@@ -448,15 +450,6 @@ class LinuxNetwork(Network):
self
.
facts
[
'all_ipv6_addresses'
]
=
ips
[
'all_ipv6_addresses'
]
self
.
facts
[
'all_ipv6_addresses'
]
=
ips
[
'all_ipv6_addresses'
]
return
self
.
facts
return
self
.
facts
def
get_ip_path
(
self
):
paths
=
[
'/sbin/ip'
,
'/usr/sbin/ip'
]
ip_path
=
None
for
path
in
paths
:
if
os
.
path
.
exists
(
path
):
ip_path
=
path
break
return
ip_path
def
get_default_interfaces
(
self
,
ip_path
):
def
get_default_interfaces
(
self
,
ip_path
):
# Use the commands:
# Use the commands:
# ip -4 route get 8.8.8.8 -> Google public DNS
# ip -4 route get 8.8.8.8 -> Google public DNS
...
@@ -730,6 +723,7 @@ def run_setup(module):
...
@@ -730,6 +723,7 @@ def run_setup(module):
return
setup_result
return
setup_result
def
main
():
def
main
():
global
module
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
()
argument_spec
=
dict
()
)
)
...
...
library/supervisorctl
View file @
b0ac7e07
...
@@ -19,20 +19,12 @@
...
@@ -19,20 +19,12 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
#
def
_find_supervisorctl
():
paths
=
[
'/usr/local/bin'
,
'/usr/bin'
]
for
p
in
paths
:
e
=
p
+
'/supervisorctl'
if
os
.
path
.
exists
(
e
):
return
e
def
_is_present
(
name
):
def
_is_present
(
name
):
rc
,
out
,
err
=
_run
(
'
%
s status'
%
_find_supervisorctl
())
rc
,
out
,
err
=
_run
(
'
%
s status'
%
_find_supervisorctl
())
return
name
in
out
return
name
in
out
def
_is_running
(
name
):
def
_is_running
(
name
,
supervisorctl
):
rc
,
out
,
err
=
_run
(
'
%
s status
%
s'
%
(
_find_supervisorctl
()
,
name
))
rc
,
out
,
err
=
_run
(
'
%
s status
%
s'
%
(
supervisorctl
,
name
))
return
'RUNNING'
in
out
return
'RUNNING'
in
out
...
@@ -55,7 +47,7 @@ def main():
...
@@ -55,7 +47,7 @@ def main():
name
=
module
.
params
[
'name'
]
name
=
module
.
params
[
'name'
]
state
=
module
.
params
[
'state'
]
state
=
module
.
params
[
'state'
]
SUPERVISORCTL
=
_find_supervisorctl
(
)
SUPERVISORCTL
=
module
.
get_bin_path
(
'supervisorctl'
,
True
)
if
SUPERVISORCTL
is
None
:
if
SUPERVISORCTL
is
None
:
module
.
fail_json
(
msg
=
'supervisorctl is not installed'
)
module
.
fail_json
(
msg
=
'supervisorctl is not installed'
)
...
@@ -74,7 +66,7 @@ def main():
...
@@ -74,7 +66,7 @@ def main():
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
running
=
_is_running
(
name
)
running
=
_is_running
(
name
,
SUPERVISORCTL
)
if
running
and
state
==
'started'
:
if
running
and
state
==
'started'
:
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
module
.
exit_json
(
changed
=
False
,
name
=
name
,
state
=
state
)
...
...
library/user
View file @
b0ac7e07
...
@@ -35,16 +35,8 @@ if os.path.exists('/etc/master.passwd'):
...
@@ -35,16 +35,8 @@ if os.path.exists('/etc/master.passwd'):
# invoke adduser in lieu of useradd, nor pw in lieu of usermod.
# invoke adduser in lieu of useradd, nor pw in lieu of usermod.
# That is, this won't work on FreeBSD.
# That is, this won't work on FreeBSD.
def
get_bin_path
(
module
,
arg
):
if
os
.
path
.
exists
(
'/usr/sbin/
%
s'
%
arg
):
return
'/usr/sbin/
%
s'
%
arg
elif
os
.
path
.
exists
(
'/sbin/
%
s'
%
arg
):
return
'/sbin/
%
s'
%
arg
else
:
module
.
fail_json
(
msg
=
"Cannot find
%
s"
%
arg
)
def
user_del
(
module
,
user
,
**
kwargs
):
def
user_del
(
module
,
user
,
**
kwargs
):
cmd
=
[
get_bin_path
(
module
,
'userdel'
)]
cmd
=
[
module
.
get_bin_path
(
'userdel'
,
True
)]
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
==
'force'
and
kwargs
[
key
]
==
'yes'
:
if
key
==
'force'
and
kwargs
[
key
]
==
'yes'
:
cmd
.
append
(
'-f'
)
cmd
.
append
(
'-f'
)
...
@@ -57,7 +49,7 @@ def user_del(module, user, **kwargs):
...
@@ -57,7 +49,7 @@ def user_del(module, user, **kwargs):
return
(
rc
,
out
,
err
)
return
(
rc
,
out
,
err
)
def
user_add
(
module
,
user
,
**
kwargs
):
def
user_add
(
module
,
user
,
**
kwargs
):
cmd
=
[
get_bin_path
(
module
,
'useradd'
)]
cmd
=
[
module
.
get_bin_path
(
'useradd'
,
True
)]
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
==
'uid'
and
kwargs
[
key
]
is
not
None
:
if
key
==
'uid'
and
kwargs
[
key
]
is
not
None
:
cmd
.
append
(
'-u'
)
cmd
.
append
(
'-u'
)
...
@@ -104,7 +96,7 @@ Without spwd, we would have to resort to reading /etc/shadow
...
@@ -104,7 +96,7 @@ Without spwd, we would have to resort to reading /etc/shadow
to get the encrypted string. For now, punt on idempotent password changes.
to get the encrypted string. For now, punt on idempotent password changes.
"""
"""
def
user_mod
(
module
,
user
,
**
kwargs
):
def
user_mod
(
module
,
user
,
**
kwargs
):
cmd
=
[
get_bin_path
(
module
,
'usermod'
)]
cmd
=
[
module
.
get_bin_path
(
'usermod'
,
True
)]
info
=
user_info
(
user
)
info
=
user_info
(
user
)
for
key
in
kwargs
:
for
key
in
kwargs
:
if
key
==
'uid'
:
if
key
==
'uid'
:
...
...
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