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
4b739313
Commit
4b739313
authored
Jul 15, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
misc code cleanup, don't pass parameters to the connection object we can already get from Runner
parent
6341e75e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
50 deletions
+43
-50
lib/ansible/runner/__init__.py
+34
-29
lib/ansible/runner/connection/__init__.py
+6
-18
lib/ansible/runner/connection/local.py
+1
-1
lib/ansible/runner/connection/paramiko_ssh.py
+1
-1
lib/ansible/runner/connection/ssh.py
+1
-1
No files found.
lib/ansible/runner/__init__.py
View file @
4b739313
...
@@ -134,10 +134,16 @@ class Runner(object):
...
@@ -134,10 +134,16 @@ class Runner(object):
inventory : inventory object, if host_list is not provided
inventory : inventory object, if host_list is not provided
"""
"""
# -- handle various parameters that need checking/mangling
if
setup_cache
is
None
:
if
setup_cache
is
None
:
setup_cache
=
collections
.
defaultdict
(
dict
)
setup_cache
=
collections
.
defaultdict
(
dict
)
if
type
(
module_args
)
not
in
[
str
,
unicode
,
dict
]:
raise
errors
.
AnsibleError
(
"module_args must be a string or dict:
%
s"
%
self
.
module_args
)
if
basedir
is
None
:
if
basedir
is
None
:
basedir
=
os
.
getcwd
()
basedir
=
os
.
getcwd
()
self
.
basedir
=
basedir
if
callbacks
is
None
:
if
callbacks
is
None
:
callbacks
=
ans_callbacks
.
DefaultRunnerCallbacks
()
callbacks
=
ans_callbacks
.
DefaultRunnerCallbacks
()
...
@@ -145,9 +151,12 @@ class Runner(object):
...
@@ -145,9 +151,12 @@ class Runner(object):
self
.
generated_jid
=
str
(
random
.
randint
(
0
,
999999999999
))
self
.
generated_jid
=
str
(
random
.
randint
(
0
,
999999999999
))
self
.
sudo_user
=
sudo_user
self
.
transport
=
transport
self
.
transport
=
transport
self
.
connector
=
connection
.
Connection
(
self
,
self
.
transport
,
self
.
sudo_user
)
if
self
.
transport
==
'ssh'
and
remote_pass
:
raise
errors
.
AnsibleError
(
"SSH transport does not support passwords, only keys or agents"
)
if
self
.
transport
==
'local'
:
self
.
remote_user
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
if
inventory
is
None
:
if
inventory
is
None
:
self
.
inventory
=
ansible
.
inventory
.
Inventory
(
host_list
)
self
.
inventory
=
ansible
.
inventory
.
Inventory
(
host_list
)
...
@@ -156,35 +165,31 @@ class Runner(object):
...
@@ -156,35 +165,31 @@ class Runner(object):
if
module_vars
is
None
:
if
module_vars
is
None
:
module_vars
=
{}
module_vars
=
{}
self
.
setup_cache
=
setup_cache
# -- save constructor parameters for later use
self
.
conditional
=
conditional
self
.
module_path
=
module_path
self
.
sudo_user
=
sudo_user
self
.
module_name
=
module_name
self
.
connector
=
connection
.
Connection
(
self
)
self
.
forks
=
int
(
forks
)
self
.
setup_cache
=
setup_cache
self
.
pattern
=
pattern
self
.
conditional
=
conditional
self
.
module_args
=
module_args
self
.
module_path
=
module_path
self
.
module_vars
=
module_vars
self
.
module_name
=
module_name
self
.
timeout
=
timeout
self
.
forks
=
int
(
forks
)
self
.
verbose
=
verbose
self
.
pattern
=
pattern
self
.
remote_user
=
remote_user
self
.
module_args
=
module_args
self
.
remote_pass
=
remote_pass
self
.
module_vars
=
module_vars
self
.
remote_port
=
remote_port
self
.
timeout
=
timeout
self
.
verbose
=
verbose
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
self
.
remote_port
=
remote_port
self
.
private_key_file
=
private_key_file
self
.
private_key_file
=
private_key_file
self
.
background
=
background
self
.
background
=
background
self
.
basedir
=
basedir
self
.
sudo
=
sudo
self
.
sudo
=
sudo
self
.
sudo_pass
=
sudo_pass
self
.
sudo_pass
=
sudo_pass
self
.
is_playbook
=
is_playbook
self
.
is_playbook
=
is_playbook
if
self
.
transport
==
'local'
:
self
.
remote_user
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
if
type
(
self
.
module_args
)
not
in
[
str
,
unicode
,
dict
]:
raise
errors
.
AnsibleError
(
"module_args must be a string or dict:
%
s"
%
self
.
module_args
)
if
self
.
transport
==
'ssh'
and
self
.
remote_pass
:
raise
errors
.
AnsibleError
(
"SSH transport does not support passwords, only keys or agents"
)
# ensure we're using unique tmp paths
random
.
seed
()
random
.
seed
()
# *****************************************************
# *****************************************************
...
...
lib/ansible/runner/connection/__init__.py
View file @
4b739313
...
@@ -18,17 +18,6 @@
...
@@ -18,17 +18,6 @@
################################################
################################################
import
warnings
import
traceback
import
os
import
time
import
re
import
shutil
import
subprocess
import
pipes
import
socket
import
random
import
local
import
local
import
paramiko_ssh
import
paramiko_ssh
import
ssh
import
ssh
...
@@ -36,19 +25,18 @@ import ssh
...
@@ -36,19 +25,18 @@ import ssh
class
Connection
(
object
):
class
Connection
(
object
):
''' Handles abstract connections to remote hosts '''
''' Handles abstract connections to remote hosts '''
def
__init__
(
self
,
runner
,
transport
,
sudo_user
):
def
__init__
(
self
,
runner
):
self
.
runner
=
runner
self
.
runner
=
runner
self
.
transport
=
transport
self
.
sudo_user
=
sudo_user
def
connect
(
self
,
host
,
port
=
None
):
def
connect
(
self
,
host
,
port
=
None
):
conn
=
None
conn
=
None
if
self
.
transport
==
'local'
:
transport
=
self
.
runner
.
transport
if
transport
==
'local'
:
conn
=
local
.
LocalConnection
(
self
.
runner
,
host
)
conn
=
local
.
LocalConnection
(
self
.
runner
,
host
)
elif
self
.
transport
==
'paramiko'
:
elif
transport
==
'paramiko'
:
conn
=
paramiko_ssh
.
ParamikoConnection
(
self
.
runner
,
host
,
port
)
conn
=
paramiko_ssh
.
ParamikoConnection
(
self
.
runner
,
host
,
port
)
elif
self
.
transport
==
'ssh'
:
elif
transport
==
'ssh'
:
conn
=
ssh
.
SSHConnection
(
self
.
runner
,
host
,
port
)
conn
=
SSHConnection
(
self
.
runner
,
host
,
port
)
if
conn
is
None
:
if
conn
is
None
:
raise
Exception
(
"unsupported connection type"
)
raise
Exception
(
"unsupported connection type"
)
return
conn
.
connect
()
return
conn
.
connect
()
...
...
lib/ansible/runner/connection/local.py
View file @
4b739313
...
@@ -43,7 +43,7 @@ class LocalConnection(object):
...
@@ -43,7 +43,7 @@ class LocalConnection(object):
return
self
return
self
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
''' run a command on the local host '''
''' run a command on the local host '''
if
self
.
runner
.
sudo
and
sudoable
:
if
self
.
runner
.
sudo
and
sudoable
:
cmd
=
"sudo -s
%
s"
%
cmd
cmd
=
"sudo -s
%
s"
%
cmd
...
...
lib/ansible/runner/connection/paramiko_ssh.py
View file @
4b739313
...
@@ -92,7 +92,7 @@ class ParamikoConnection(object):
...
@@ -92,7 +92,7 @@ class ParamikoConnection(object):
self
.
ssh
=
self
.
_get_conn
()
self
.
ssh
=
self
.
_get_conn
()
return
self
return
self
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
''' run a command on the remote host '''
''' run a command on the remote host '''
bufsize
=
4096
bufsize
=
4096
...
...
lib/ansible/runner/connection/ssh.py
View file @
4b739313
...
@@ -56,7 +56,7 @@ class SSHConnection(object):
...
@@ -56,7 +56,7 @@ class SSHConnection(object):
return
self
return
self
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
''' run a command on the remote host '''
''' run a command on the remote host '''
ssh_cmd
=
[
"ssh"
,
"-tt"
,
"-q"
]
+
self
.
common_args
+
[
self
.
host
]
ssh_cmd
=
[
"ssh"
,
"-tt"
,
"-q"
]
+
self
.
common_args
+
[
self
.
host
]
...
...
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