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
b2e8084c
Commit
b2e8084c
authored
Feb 24, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4 from skvidal/master
adds an option to ask for and store the ssh password from the cli
parents
a0210209
08b45d6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
bin/ansible
+8
-0
lib/ansible/__init__.py
+5
-2
No files found.
bin/ansible
View file @
b2e8084c
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
from
optparse
import
OptionParser
from
optparse
import
OptionParser
import
json
import
json
import
os
import
os
import
getpass
import
ansible
import
ansible
DEFAULT_HOST_LIST
=
'/etc/ansible/hosts'
DEFAULT_HOST_LIST
=
'/etc/ansible/hosts'
...
@@ -41,6 +42,8 @@ class Cli(object):
...
@@ -41,6 +42,8 @@ class Cli(object):
def
runner
(
self
):
def
runner
(
self
):
parser
=
OptionParser
()
parser
=
OptionParser
()
parser
.
add_option
(
"-P"
,
"--askpass"
,
default
=
False
,
action
=
"store_true"
,
help
=
"ask the user to input the ssh password for connecting"
)
parser
.
add_option
(
"-H"
,
"--host-list"
,
dest
=
"host_list"
,
parser
.
add_option
(
"-H"
,
"--host-list"
,
dest
=
"host_list"
,
help
=
"path to hosts list"
,
default
=
DEFAULT_HOST_LIST
)
help
=
"path to hosts list"
,
default
=
DEFAULT_HOST_LIST
)
parser
.
add_option
(
"-L"
,
"--library"
,
dest
=
"module_path"
,
parser
.
add_option
(
"-L"
,
"--library"
,
dest
=
"module_path"
,
...
@@ -61,11 +64,16 @@ class Cli(object):
...
@@ -61,11 +64,16 @@ class Cli(object):
# TODO: more shell like splitting on module_args would
# TODO: more shell like splitting on module_args would
# be a good idea
# be a good idea
sshpass
=
None
if
options
.
askpass
:
sshpass
=
getpass
.
getpass
(
prompt
=
"SSH password: "
)
return
ansible
.
Runner
(
return
ansible
.
Runner
(
module_name
=
options
.
module_name
,
module_name
=
options
.
module_name
,
module_path
=
options
.
module_path
,
module_path
=
options
.
module_path
,
module_args
=
options
.
module_args
.
split
(
' '
),
module_args
=
options
.
module_args
.
split
(
' '
),
remote_user
=
options
.
remote_user
,
remote_user
=
options
.
remote_user
,
remote_pass
=
sshpass
,
host_list
=
options
.
host_list
,
host_list
=
options
.
host_list
,
forks
=
options
.
forks
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
pattern
=
options
.
pattern
,
...
...
lib/ansible/__init__.py
View file @
b2e8084c
...
@@ -36,6 +36,7 @@ DEFAULT_FORKS = 3
...
@@ -36,6 +36,7 @@ DEFAULT_FORKS = 3
DEFAULT_MODULE_ARGS
=
''
DEFAULT_MODULE_ARGS
=
''
DEFAULT_TIMEOUT
=
60
DEFAULT_TIMEOUT
=
60
DEFAULT_REMOTE_USER
=
'root'
DEFAULT_REMOTE_USER
=
'root'
DEFAULT_REMOTE_PASS
=
None
def
_executor_hook
(
x
):
def
_executor_hook
(
x
):
''' callback used by multiprocessing pool '''
''' callback used by multiprocessing pool '''
...
@@ -53,6 +54,7 @@ class Runner(object):
...
@@ -53,6 +54,7 @@ class Runner(object):
timeout
=
DEFAULT_TIMEOUT
,
timeout
=
DEFAULT_TIMEOUT
,
pattern
=
DEFAULT_PATTERN
,
pattern
=
DEFAULT_PATTERN
,
remote_user
=
DEFAULT_REMOTE_USER
,
remote_user
=
DEFAULT_REMOTE_USER
,
remote_pass
=
DEFAULT_REMOTE_PASS
,
verbose
=
False
):
verbose
=
False
):
...
@@ -69,6 +71,7 @@ class Runner(object):
...
@@ -69,6 +71,7 @@ class Runner(object):
self
.
timeout
=
timeout
self
.
timeout
=
timeout
self
.
verbose
=
verbose
self
.
verbose
=
verbose
self
.
remote_user
=
remote_user
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
def
_parse_hosts
(
self
,
host_list
):
def
_parse_hosts
(
self
,
host_list
):
''' parse the host inventory file if not sent as an array '''
''' parse the host inventory file if not sent as an array '''
...
@@ -95,8 +98,8 @@ class Runner(object):
...
@@ -95,8 +98,8 @@ class Runner(object):
ssh
=
paramiko
.
SSHClient
()
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
try
:
ssh
.
connect
(
host
,
username
=
self
.
remote_user
,
ssh
.
connect
(
host
,
username
=
self
.
remote_user
,
allow_agent
=
True
,
allow_agent
=
True
,
look_for_keys
=
True
)
look_for_keys
=
True
,
password
=
self
.
remote_pass
)
return
[
True
,
ssh
]
return
[
True
,
ssh
]
except
:
except
:
return
[
False
,
traceback
.
format_exc
()
]
return
[
False
,
traceback
.
format_exc
()
]
...
...
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