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
7eb2dd2d
Commit
7eb2dd2d
authored
Feb 23, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add remote setting to file, update TODO
parent
03647d64
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
19 deletions
+29
-19
TODO.md
+2
-3
bin/ansible
+5
-1
lib/ansible/__init__.py
+22
-15
No files found.
TODO.md
View file @
7eb2dd2d
TODO list and plans
===================
*
make remote user settable versus assuming remote login is named root
*
modules for users, groups, and files, using puppet style ensure mechanics
*
ansible-inventory -
-
gathering fact/hw info, storing in git, adding RSS
*
ansible-slurp -
-----
recursively rsync file trees for each host
*
ansible-inventory - gathering fact/hw info, storing in git, adding RSS
*
ansible-slurp - recursively rsync file trees for each host
*
very simple option constructing/parsing for modules
*
Dead-simple declarative configuration management engine using
a runbook style recipe file, written in JSON or YAML
...
...
bin/ansible
View file @
7eb2dd2d
...
...
@@ -32,6 +32,7 @@ DEFAULT_MODULE_NAME = 'ping'
DEFAULT_PATTERN
=
'*'
DEFAULT_FORKS
=
3
DEFAULT_MODULE_ARGS
=
''
DEFAULT_REMOTE_USER
=
'root'
class
Cli
(
object
):
...
...
@@ -44,7 +45,7 @@ class Cli(object):
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"
,
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
)
...
...
@@ -52,6 +53,8 @@ class Cli(object):
help
=
"module arguments"
,
default
=
DEFAULT_MODULE_ARGS
)
parser
.
add_option
(
"-p"
,
"--pattern"
,
dest
=
"pattern"
,
help
=
"hostname pattern"
,
default
=
DEFAULT_PATTERN
)
parser
.
add_option
(
"-u"
,
"--remote-user"
,
dest
=
"remote_user"
,
help
=
"remote username"
,
default
=
DEFAULT_REMOTE_USER
)
options
,
args
=
parser
.
parse_args
()
...
...
@@ -62,6 +65,7 @@ class Cli(object):
module_name
=
options
.
module_name
,
module_path
=
options
.
module_path
,
module_args
=
options
.
module_args
.
split
(
' '
),
remote_user
=
options
.
remote_user
,
host_list
=
options
.
host_list
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
...
...
lib/ansible/__init__.py
View file @
7eb2dd2d
...
...
@@ -36,6 +36,7 @@ DEFAULT_PATTERN = '*'
DEFAULT_FORKS
=
3
DEFAULT_MODULE_ARGS
=
''
DEFAULT_TIMEOUT
=
60
DEFAULT_REMOTE_USER
=
'root'
class
Pooler
(
object
):
...
...
@@ -66,6 +67,7 @@ class Runner(object):
forks
=
DEFAULT_FORKS
,
timeout
=
DEFAULT_TIMEOUT
,
pattern
=
DEFAULT_PATTERN
,
remote_user
=
DEFAULT_REMOTE_USER
,
verbose
=
False
):
...
...
@@ -81,6 +83,7 @@ class Runner(object):
self
.
module_args
=
module_args
self
.
timeout
=
timeout
self
.
verbose
=
verbose
self
.
remote_user
=
remote_user
def
_parse_hosts
(
self
,
host_list
):
''' parse the host inventory file if not sent as an array '''
...
...
@@ -103,23 +106,19 @@ class Runner(object):
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
ssh
.
connect
(
host
,
username
=
'root'
,
ssh
.
connect
(
host
,
username
=
self
.
remote_user
,
allow_agent
=
True
,
look_for_keys
=
True
)
return
ssh
return
[
True
,
ssh
]
except
:
# TODO -- just convert traceback to string
# and return a seperate hash of failed hosts
if
self
.
verbose
:
traceback
.
print_exc
()
return
None
return
[
False
,
traceback
.
format_exc
()
]
def
_executor
(
self
,
host
):
''' callback executed in parallel for each host '''
# TODO: try/catch returning none
conn
=
self
.
_connect
(
host
)
if
not
conn
:
return
[
host
,
None
]
ok
,
conn
=
self
.
_connect
(
host
)
if
not
ok
:
return
[
host
,
False
,
conn
]
if
self
.
module_name
!=
"copy"
:
# transfer a module, set it executable, and run it
...
...
@@ -127,15 +126,14 @@ class Runner(object):
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
cmd
=
self
.
_command
(
outpath
)
result
=
self
.
_exec_command
(
conn
,
cmd
)
re
sult
=
json
.
loads
(
result
)
re
turn
[
host
,
True
,
json
.
loads
(
result
)
]
else
:
# SFTP file copy module is not really a module
ftp
=
conn
.
open_sftp
()
ftp
.
put
(
self
.
module_args
[
0
],
self
.
module_args
[
1
])
ftp
.
close
()
return
[
host
,
1
]
return
[
host
,
True
,
1
]
return
[
host
,
result
]
def
_command
(
self
,
outpath
):
''' form up a command string '''
...
...
@@ -168,8 +166,17 @@ class Runner(object):
def
executor
(
x
):
return
self
.
_executor
(
x
)
results
=
Pooler
.
parmap
(
executor
,
hosts
)
by_host
=
dict
(
results
)
return
by_host
results2
=
{
"successful"
:
{},
"failed"
:
{}
}
for
x
in
results
:
(
host
,
is_ok
,
result
)
=
x
if
not
is_ok
:
results2
[
"failed"
][
host
]
=
result
else
:
results2
[
"successful"
][
host
]
=
result
return
results2
if
__name__
==
'__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