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
a5df306a
Commit
a5df306a
authored
Apr 12, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #132 from sfromm/localconnection
Make use of LocalConnection explicit
parents
ecef6671
0675f251
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
17 deletions
+50
-17
bin/ansible
+2
-2
docs/man/man1/ansible.1
+10
-2
docs/man/man1/ansible.1.asciidoc
+4
-0
lib/ansible/connection.py
+1
-1
lib/ansible/constants.py
+2
-0
lib/ansible/playbook.py
+16
-9
lib/ansible/runner.py
+8
-2
lib/ansible/utils.py
+7
-1
No files found.
bin/ansible
View file @
a5df306a
...
...
@@ -48,7 +48,7 @@ class Cli(object):
''' create an options parser for bin/ansible '''
parser
=
utils
.
base_parser
(
constants
=
C
,
runas_opts
=
True
,
async_opts
=
True
,
output_opts
=
True
,
usage
=
'
%
prog <host-pattern> [options]'
)
output_opts
=
True
,
connect_opts
=
True
,
usage
=
'
%
prog <host-pattern> [options]'
)
parser
.
add_option
(
'-a'
,
'--args'
,
dest
=
'module_args'
,
help
=
"module arguments"
,
default
=
C
.
DEFAULT_MODULE_ARGS
)
parser
.
add_option
(
'-m'
,
'--module-name'
,
dest
=
'module_name'
,
...
...
@@ -86,7 +86,7 @@ class Cli(object):
remote_port
=
options
.
remote_port
,
forks
=
options
.
forks
,
background
=
options
.
seconds
,
pattern
=
pattern
,
callbacks
=
self
.
callbacks
,
sudo
=
options
.
sudo
,
verbose
=
True
,
debug
=
options
.
debug
transport
=
options
.
connection
,
debug
=
options
.
debug
)
return
(
runner
,
runner
.
run
())
...
...
docs/man/man1/ansible.1
View file @
a5df306a
...
...
@@ -2,12 +2,12 @@
.\" Title: ansible
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\" Date: 04/
03
/2012
.\" Date: 04/
10
/2012
.\" Manual: System administration commands
.\" Source: Ansible 0.0.2
.\" Language: English
.\"
.TH "ANSIBLE" "1" "04/
03
/2012" "Ansible 0\&.0\&.2" "System administration commands"
.TH "ANSIBLE" "1" "04/
10
/2012" "Ansible 0\&.0\&.2" "System administration commands"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
...
...
@@ -122,6 +122,14 @@ Use this remote
\fIUSERNAME\fR
instead of root\&.
.RE
.PP
\fB\-c\fR \fICONNECTION\fR, \fB\-\-connection=\fR\fICONNECTION\fR
.RS 4
Connection type to use\&. Possible options are
\fIparamiko\fR
and
\fIlocal\fR\&.
.RE
.SH "INVENTORY"
.sp
Ansible stores the hosts it can potentially operate on in an inventory file\&. The syntax is one host per line\&. Groups headers are allowed and are included on their own line, enclosed in square brackets\&.
...
...
docs/man/man1/ansible.1.asciidoc
View file @
a5df306a
...
...
@@ -96,6 +96,10 @@ Poll a background job every 'NUM' seconds. Requires *-B*.
Use this remote 'USERNAME' instead of root.
*-c* 'CONNECTION', *--connection=*'CONNECTION'::
Connection type to use. Possible options are 'paramiko' and 'local'.
INVENTORY
---------
...
...
lib/ansible/connection.py
View file @
a5df306a
...
...
@@ -47,7 +47,7 @@ class Connection(object):
def
connect
(
self
,
host
):
conn
=
None
if
self
.
transport
==
'local'
or
self
.
_LOCALHOSTRE
.
search
(
host
):
if
self
.
transport
==
'local'
and
self
.
_LOCALHOSTRE
.
search
(
host
):
conn
=
LocalConnection
(
self
.
runner
,
host
)
elif
self
.
transport
==
'paramiko'
:
conn
=
ParamikoConnection
(
self
.
runner
,
host
)
...
...
lib/ansible/constants.py
View file @
a5df306a
...
...
@@ -33,3 +33,5 @@ DEFAULT_POLL_INTERVAL = 15
DEFAULT_REMOTE_USER
=
'root'
DEFAULT_REMOTE_PASS
=
None
DEFAULT_REMOTE_PORT
=
22
DEFAULT_TRANSPORT
=
'paramiko'
DEFAULT_TRANSPORT_OPTS
=
[
'local'
,
'paramiko'
]
lib/ansible/playbook.py
View file @
a5df306a
...
...
@@ -55,6 +55,7 @@ class PlayBook(object):
remote_user
=
C
.
DEFAULT_REMOTE_USER
,
remote_pass
=
C
.
DEFAULT_REMOTE_PASS
,
remote_port
=
C
.
DEFAULT_REMOTE_PORT
,
transport
=
C
.
DEFAULT_TRANSPORT
,
override_hosts
=
None
,
extra_vars
=
None
,
debug
=
False
,
...
...
@@ -73,6 +74,7 @@ class PlayBook(object):
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
self
.
remote_port
=
remote_port
self
.
transport
=
transport
self
.
debug
=
debug
self
.
verbose
=
verbose
self
.
callbacks
=
callbacks
...
...
@@ -272,7 +274,7 @@ class PlayBook(object):
# *****************************************************
def
_run_module
(
self
,
pattern
,
host_list
,
module
,
args
,
vars
,
remote_user
,
async_seconds
,
async_poll_interval
,
only_if
,
sudo
):
async_seconds
,
async_poll_interval
,
only_if
,
sudo
,
transport
):
''' run a particular module step in a playbook '''
hosts
=
[
h
for
h
in
host_list
if
(
h
not
in
self
.
stats
.
failures
)
and
(
h
not
in
self
.
stats
.
dark
)]
...
...
@@ -285,7 +287,8 @@ class PlayBook(object):
remote_port
=
self
.
remote_port
,
module_vars
=
vars
,
setup_cache
=
SETUP_CACHE
,
basedir
=
self
.
basedir
,
conditional
=
only_if
,
callbacks
=
self
.
runner_callbacks
,
extra_vars
=
self
.
extra_vars
,
debug
=
self
.
debug
,
sudo
=
sudo
extra_vars
=
self
.
extra_vars
,
debug
=
self
.
debug
,
sudo
=
sudo
,
transport
=
transport
)
if
async_seconds
==
0
:
...
...
@@ -296,7 +299,7 @@ class PlayBook(object):
# *****************************************************
def
_run_task
(
self
,
pattern
=
None
,
host_list
=
None
,
task
=
None
,
remote_user
=
None
,
handlers
=
None
,
conditional
=
False
,
sudo
=
False
):
remote_user
=
None
,
handlers
=
None
,
conditional
=
False
,
sudo
=
False
,
transport
=
None
):
''' run a single task in the playbook and recursively run any subtasks. '''
# load the module name and parameters from the task entry
...
...
@@ -328,7 +331,7 @@ class PlayBook(object):
# run the task in parallel
results
=
self
.
_run_module
(
pattern
,
host_list
,
module_name
,
module_args
,
module_vars
,
remote_user
,
async_seconds
,
async_poll_interval
,
only_if
,
sudo
)
async_poll_interval
,
only_if
,
sudo
,
transport
)
self
.
stats
.
compute
(
results
)
...
...
@@ -423,7 +426,7 @@ class PlayBook(object):
# *****************************************************
def
_do_setup_step
(
self
,
pattern
,
vars
,
user
,
port
,
sudo
,
vars_files
=
None
):
def
_do_setup_step
(
self
,
pattern
,
vars
,
user
,
port
,
sudo
,
transport
,
vars_files
=
None
):
''' push variables down to the systems and get variables+facts back up '''
# this enables conditional includes like $facter_os.yml and is only done
...
...
@@ -447,6 +450,7 @@ class PlayBook(object):
remote_pass
=
self
.
remote_pass
,
remote_port
=
self
.
remote_port
,
setup_cache
=
SETUP_CACHE
,
callbacks
=
self
.
runner_callbacks
,
sudo
=
sudo
,
debug
=
self
.
debug
,
transport
=
transport
,
)
.
run
()
self
.
stats
.
compute
(
setup_results
,
setup
=
True
)
...
...
@@ -486,15 +490,16 @@ class PlayBook(object):
user
=
pg
.
get
(
'user'
,
self
.
remote_user
)
port
=
pg
.
get
(
'port'
,
self
.
remote_port
)
sudo
=
pg
.
get
(
'sudo'
,
False
)
transport
=
pg
.
get
(
'connection'
,
self
.
transport
)
self
.
callbacks
.
on_play_start
(
pattern
)
# push any variables down to the system # and get facts/ohai/other data back up
self
.
_do_setup_step
(
pattern
,
vars
,
user
,
port
,
sudo
,
None
)
self
.
_do_setup_step
(
pattern
,
vars
,
user
,
port
,
sudo
,
transport
,
None
)
# now with that data, handle contentional variable file imports!
if
len
(
vars_files
)
>
0
:
self
.
_do_setup_step
(
pattern
,
vars
,
user
,
port
,
sudo
,
vars_files
)
self
.
_do_setup_step
(
pattern
,
vars
,
user
,
port
,
sudo
,
transport
,
vars_files
)
# run all the top level tasks, these get run on every node
for
task
in
tasks
:
...
...
@@ -504,7 +509,8 @@ class PlayBook(object):
task
=
task
,
handlers
=
handlers
,
remote_user
=
user
,
sudo
=
sudo
sudo
=
sudo
,
transport
=
transport
)
# handlers only run on certain nodes, they are flagged by _flag_handlers
...
...
@@ -523,7 +529,8 @@ class PlayBook(object):
host_list
=
triggered_by
,
conditional
=
True
,
remote_user
=
user
,
sudo
=
sudo
sudo
=
sudo
,
transport
=
transport
)
# end of execution for this particular pattern. Multiple patterns
...
...
lib/ansible/runner.py
View file @
a5df306a
...
...
@@ -22,6 +22,7 @@ import fnmatch
import
multiprocessing
import
signal
import
os
import
pwd
import
Queue
import
random
import
traceback
...
...
@@ -73,7 +74,7 @@ class Runner(object):
forks
=
C
.
DEFAULT_FORKS
,
timeout
=
C
.
DEFAULT_TIMEOUT
,
pattern
=
C
.
DEFAULT_PATTERN
,
remote_user
=
C
.
DEFAULT_REMOTE_USER
,
remote_pass
=
C
.
DEFAULT_REMOTE_PASS
,
remote_port
=
C
.
DEFAULT_REMOTE_PORT
,
background
=
0
,
basedir
=
None
,
setup_cache
=
None
,
transport
=
'paramiko'
,
conditional
=
'True'
,
groups
=
{},
callbacks
=
None
,
verbose
=
False
,
transport
=
C
.
DEFAULT_TRANSPORT
,
conditional
=
'True'
,
groups
=
{},
callbacks
=
None
,
verbose
=
False
,
debug
=
False
,
sudo
=
False
,
extra_vars
=
None
,
module_vars
=
None
):
if
setup_cache
is
None
:
...
...
@@ -86,7 +87,9 @@ class Runner(object):
self
.
callbacks
=
callbacks
self
.
generated_jid
=
str
(
random
.
randint
(
0
,
999999999999
))
self
.
connector
=
ansible
.
connection
.
Connection
(
self
,
transport
)
self
.
transport
=
transport
self
.
connector
=
ansible
.
connection
.
Connection
(
self
,
self
.
transport
)
if
type
(
host_list
)
==
str
:
self
.
host_list
,
self
.
groups
=
self
.
parse_hosts
(
host_list
)
...
...
@@ -113,6 +116,9 @@ class Runner(object):
self
.
basedir
=
basedir
self
.
sudo
=
sudo
euid
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
if
self
.
transport
==
'local'
and
self
.
remote_user
!=
euid
:
raise
Exception
(
"User mismatch: expected
%
s, but is
%
s"
%
(
self
.
remote_user
,
euid
))
if
type
(
self
.
module_args
)
!=
str
and
type
(
self
.
module_args
)
!=
dict
:
raise
Exception
(
"module_args must be a string or dict:
%
s"
%
self
.
module_args
)
...
...
lib/ansible/utils.py
View file @
a5df306a
...
...
@@ -279,7 +279,7 @@ class SortedOptParser(optparse.OptionParser):
self
.
option_list
.
sort
(
key
=
methodcaller
(
'get_opt_string'
))
return
optparse
.
OptionParser
.
format_help
(
self
,
formatter
=
None
)
def
base_parser
(
constants
=
C
,
usage
=
""
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
):
def
base_parser
(
constants
=
C
,
usage
=
""
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
,
connect_opts
=
False
):
''' create an options parser for any ansible script '''
parser
=
SortedOptParser
(
usage
)
...
...
@@ -310,6 +310,12 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, asyn
parser
.
add_option
(
'-u'
,
'--user'
,
default
=
constants
.
DEFAULT_REMOTE_USER
,
dest
=
'remote_user'
,
help
=
'connect as this user'
)
if
connect_opts
:
parser
.
add_option
(
'-c'
,
'--connection'
,
dest
=
'connection'
,
choices
=
C
.
DEFAULT_TRANSPORT_OPTS
,
default
=
C
.
DEFAULT_TRANSPORT
,
help
=
"connection type to use"
)
if
async_opts
:
parser
.
add_option
(
'-P'
,
'--poll'
,
default
=
constants
.
DEFAULT_POLL_INTERVAL
,
type
=
'int'
,
dest
=
'poll_interval'
,
help
=
'set the poll interval if using -B'
)
...
...
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