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
145a024d
Commit
145a024d
authored
Feb 23, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split CLI into binscript
parent
288ce6b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
55 deletions
+71
-55
bin/ansible
+56
-0
lib/ansible/__init__.py
+15
-55
No files found.
bin/ansible
0 → 100755
View file @
145a024d
#!/usr/bin/python
from
optparse
import
OptionParser
import
json
import
os
import
ansible
DEFAULT_HOST_LIST
=
'~/.ansible_hosts'
DEFAULT_MODULE_PATH
=
'~/ansible'
DEFAULT_MODULE_NAME
=
'ping'
DEFAULT_PATTERN
=
'*'
DEFAULT_FORKS
=
3
DEFAULT_MODULE_ARGS
=
''
class
Cli
(
object
):
def
__init__
(
self
):
pass
def
runner
(
self
):
parser
=
OptionParser
()
parser
.
add_option
(
"-H"
,
"--host-list"
,
dest
=
"host_list"
,
help
=
"path to hosts list"
,
default
=
DEFAULT_HOST_LIST
)
parser
.
add_option
(
"-L"
,
"--library"
,
dest
=
"module_path"
,
help
=
"path to module library"
,
default
=
DEFAULT_MODULE_PATH
)
parser
.
add_option
(
"-F"
,
"--forks"
,
dest
=
"forks"
,
help
=
"level of parallelism"
,
default
=
DEFAULT_FORKS
)
parser
.
add_option
(
"-n"
,
"--name"
,
dest
=
"module_name"
,
help
=
"module name to execute"
,
default
=
DEFAULT_MODULE_NAME
)
parser
.
add_option
(
"-a"
,
"--args"
,
dest
=
"module_args"
,
help
=
"module arguments"
,
default
=
DEFAULT_MODULE_ARGS
)
parser
.
add_option
(
"-p"
,
"--pattern"
,
dest
=
"pattern"
,
help
=
"hostname pattern"
,
default
=
DEFAULT_PATTERN
)
options
,
args
=
parser
.
parse_args
()
host_list
=
self
.
_host_list
(
options
.
host_list
)
return
ansible
.
Runner
(
module_name
=
options
.
module_name
,
module_path
=
options
.
module_path
,
module_args
=
options
.
module_args
,
host_list
=
host_list
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
)
def
_host_list
(
self
,
host_list
):
host_list
=
os
.
path
.
expanduser
(
host_list
)
return
file
(
host_list
)
.
read
()
.
split
(
"
\n
"
)
if
__name__
==
'__main__'
:
result
=
Cli
()
.
runner
()
.
run
()
print
json
.
dumps
(
result
,
sort_keys
=
True
,
indent
=
4
)
lib/ansible/__init__.py
100644 → 100755
View file @
145a024d
# core
from
optparse
import
OptionParser
import
fnmatch
from
multiprocessing
import
Process
,
Pipe
from
itertools
import
izip
...
...
@@ -9,6 +7,9 @@ import json
# non-core
import
paramiko
# TODO -- library should have defaults, not just CLI
# update Runner constructor below to use
DEFAULT_HOST_LIST
=
'~/.ansible_hosts'
DEFAULT_MODULE_PATH
=
'~/ansible'
DEFAULT_MODULE_NAME
=
'ping'
...
...
@@ -35,43 +36,6 @@ class Pooler(object):
[
p
.
join
()
for
p
in
proc
]
return
[
p
.
recv
()
for
(
p
,
c
)
in
pipe
]
class
Cli
(
object
):
def
__init__
(
self
):
pass
def
runner
(
self
):
parser
=
OptionParser
()
parser
.
add_option
(
"-H"
,
"--host-list"
,
dest
=
"host_list"
,
help
=
"path to hosts list"
,
default
=
DEFAULT_HOST_LIST
)
parser
.
add_option
(
"-L"
,
"--library"
,
dest
=
"module_path"
,
help
=
"path to module library"
,
default
=
DEFAULT_MODULE_PATH
)
parser
.
add_option
(
"-F"
,
"--forks"
,
dest
=
"forks"
,
help
=
"level of parallelism"
,
default
=
DEFAULT_FORKS
)
parser
.
add_option
(
"-n"
,
"--name"
,
dest
=
"module_name"
,
help
=
"module name to execute"
,
default
=
DEFAULT_MODULE_NAME
)
parser
.
add_option
(
"-a"
,
"--args"
,
dest
=
"module_args"
,
help
=
"module arguments"
,
default
=
DEFAULT_MODULE_ARGS
)
parser
.
add_option
(
"-p"
,
"--pattern"
,
dest
=
"pattern"
,
help
=
"hostname pattern"
,
default
=
DEFAULT_PATTERN
)
options
,
args
=
parser
.
parse_args
()
host_list
=
self
.
_host_list
(
options
.
host_list
)
return
Runner
(
module_name
=
options
.
module_name
,
module_path
=
options
.
module_path
,
module_args
=
options
.
module_args
,
host_list
=
host_list
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
)
def
_host_list
(
self
,
host_list
):
host_list
=
os
.
path
.
expanduser
(
host_list
)
return
file
(
host_list
)
.
read
()
.
split
(
"
\n
"
)
class
Runner
(
object
):
def
__init__
(
self
,
host_list
=
[],
module_path
=
None
,
...
...
@@ -144,22 +108,18 @@ class Runner(object):
if
__name__
==
'__main__'
:
# comamnd line usage example:
result
=
Cli
()
.
runner
()
.
run
()
print
json
.
dumps
(
result
,
sort_keys
=
True
,
indent
=
4
)
# API usage example:
#r = Runner(
# host_list = [ '127.0.0.1' ],
# module_path='~/.ansible',
# module_name='ping',
# module_args='',
# pattern='*',
# forks=3
#)
#print r.run()
# TODO: if host list is string load from file
r
=
Runner
(
host_list
=
[
'127.0.0.1'
],
module_path
=
'~/ansible'
,
module_name
=
'ping'
,
module_args
=
''
,
pattern
=
'*'
,
forks
=
3
)
print
r
.
run
()
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