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
227c500a
Commit
227c500a
authored
Jul 15, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Misc cleanup/formatting
parent
867b2437
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
28 deletions
+33
-28
lib/ansible/runner/__init__.py
+33
-28
No files found.
lib/ansible/runner/__init__.py
View file @
227c500a
...
@@ -70,6 +70,7 @@ def _executor_hook(job_queue, result_queue):
...
@@ -70,6 +70,7 @@ def _executor_hook(job_queue, result_queue):
################################################
################################################
class
ReturnData
(
object
):
class
ReturnData
(
object
):
''' internal return class for execute methods, not part of API signature '''
__slots__
=
[
'result'
,
'comm_ok'
,
'host'
]
__slots__
=
[
'result'
,
'comm_ok'
,
'host'
]
...
@@ -100,6 +101,7 @@ class ReturnData(object):
...
@@ -100,6 +101,7 @@ class ReturnData(object):
return
True
return
True
class
Runner
(
object
):
class
Runner
(
object
):
''' core API interface to ansible '''
def
__init__
(
self
,
def
__init__
(
self
,
host_list
=
C
.
DEFAULT_HOST_LIST
,
module_path
=
C
.
DEFAULT_MODULE_PATH
,
host_list
=
C
.
DEFAULT_HOST_LIST
,
module_path
=
C
.
DEFAULT_MODULE_PATH
,
...
@@ -114,29 +116,29 @@ class Runner(object):
...
@@ -114,29 +116,29 @@ class Runner(object):
module_vars
=
None
,
is_playbook
=
False
,
inventory
=
None
):
module_vars
=
None
,
is_playbook
=
False
,
inventory
=
None
):
"""
"""
host_list : path to a host list file, like /etc/ansible/hosts
host_list
: path to a host list file, like /etc/ansible/hosts
module_path : path to modules, like /usr/share/ansible
module_path
: path to modules, like /usr/share/ansible
module_name : which module to run (string)
module_name
: which module to run (string)
module_args : args to pass to the module (string)
module_args
: args to pass to the module (string)
forks : desired level of paralellism (hosts to run on at a time)
forks
: desired level of paralellism (hosts to run on at a time)
timeout : connection timeout, such as a SSH timeout, in seconds
timeout
: connection timeout, such as a SSH timeout, in seconds
pattern : pattern or groups to select from in inventory
pattern
: pattern or groups to select from in inventory
remote_user : connect as this remote username
remote_user
: connect as this remote username
remote_pass : supply this password (if not using keys)
remote_pass
: supply this password (if not using keys)
remote_port : use this default remote port (if not set by the inventory system)
remote_port
: use this default remote port (if not set by the inventory system)
private_key_file
: use this private key as your auth key
private_key_file : use this private key as your auth key
sudo_user : If you want to sudo to a user other than root.
sudo_user
: If you want to sudo to a user other than root.
sudo_pass : sudo password if using sudo and sudo requires a password
sudo_pass
: sudo password if using sudo and sudo requires a password
background : run asynchronously with a cap of this many # of seconds (if not 0)
background
: run asynchronously with a cap of this many # of seconds (if not 0)
basedir : paths used by modules if not absolute are relative to here
basedir
: paths used by modules if not absolute are relative to here
setup_cache : this is a internalism that is going away
setup_cache
: this is a internalism that is going away
transport : transport mode (paramiko, local)
transport
: transport mode (paramiko, local)
conditional : only execute if this string, evaluated, is True
conditional
: only execute if this string, evaluated, is True
callbacks : output callback class
callbacks
: output callback class
sudo : log in as remote user and immediately sudo to root
sudo
: log in as remote user and immediately sudo to root
module_vars : provides additional variables to a template.
module_vars
: provides additional variables to a template.
is_playbook : indicates Runner is being used by a playbook. affects behavior in various ways.
is_playbook
: indicates Runner is being used by a playbook. affects behavior in various ways.
inventory : inventory object, if host_list is not provided
inventory
: inventory object, if host_list is not provided
"""
"""
if
setup_cache
is
None
:
if
setup_cache
is
None
:
...
@@ -182,15 +184,14 @@ class Runner(object):
...
@@ -182,15 +184,14 @@ class Runner(object):
self
.
sudo_pass
=
sudo_pass
self
.
sudo_pass
=
sudo_pass
self
.
is_playbook
=
is_playbook
self
.
is_playbook
=
is_playbook
euid
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
if
self
.
transport
==
'local'
:
if
self
.
transport
==
'local'
and
self
.
remote_user
!=
euid
:
self
.
remote_user
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
raise
errors
.
AnsibleError
(
"User mismatch: expected
%
s, but is
%
s"
%
(
self
.
remote_user
,
euid
))
if
type
(
self
.
module_args
)
not
in
[
str
,
unicode
,
dict
]:
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
)
raise
errors
.
AnsibleError
(
"module_args must be a string or dict:
%
s"
%
self
.
module_args
)
if
self
.
transport
==
'ssh'
and
self
.
remote_pass
:
if
self
.
transport
==
'ssh'
and
self
.
remote_pass
:
raise
errors
.
AnsibleError
(
"SSH transport does not support
remote
passwords, only keys or agents"
)
raise
errors
.
AnsibleError
(
"SSH transport does not support passwords, only keys or agents"
)
self
.
_tmp_paths
=
{}
random
.
seed
()
random
.
seed
()
# *****************************************************
# *****************************************************
...
@@ -638,6 +639,8 @@ class Runner(object):
...
@@ -638,6 +639,8 @@ class Runner(object):
self
.
callbacks
.
on_unreachable
(
host
,
msg
)
self
.
callbacks
.
on_unreachable
(
host
,
msg
)
return
ReturnData
(
host
=
host
,
comm_ok
=
False
,
result
=
dict
(
failed
=
True
,
msg
=
msg
))
return
ReturnData
(
host
=
host
,
comm_ok
=
False
,
result
=
dict
(
failed
=
True
,
msg
=
msg
))
# *****************************************************
def
_executor_internal
(
self
,
host
):
def
_executor_internal
(
self
,
host
):
''' callback executed in parallel for each host. returns (hostname, connected_ok, extra) '''
''' callback executed in parallel for each host. returns (hostname, connected_ok, extra) '''
...
@@ -860,6 +863,8 @@ class Runner(object):
...
@@ -860,6 +863,8 @@ class Runner(object):
results
=
[
self
.
_executor
(
h
[
1
])
for
h
in
hosts
]
results
=
[
self
.
_executor
(
h
[
1
])
for
h
in
hosts
]
return
self
.
_partition_results
(
results
)
return
self
.
_partition_results
(
results
)
# *****************************************************
def
run_async
(
self
,
time_limit
):
def
run_async
(
self
,
time_limit
):
''' Run this module asynchronously and return a poller. '''
''' Run this module asynchronously and return a poller. '''
self
.
background
=
time_limit
self
.
background
=
time_limit
...
...
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