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
9df612f0
Commit
9df612f0
authored
Mar 24, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a "-o" override option so hosts not in a playbook can still be managed by a playbook.
parent
b213437b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
22 deletions
+40
-22
bin/ansible-playbook
+7
-1
lib/ansible/playbook.py
+27
-20
lib/ansible/runner.py
+6
-1
No files found.
bin/ansible-playbook
View file @
9df612f0
...
...
@@ -50,6 +50,8 @@ def main(args):
help
=
"ask for SSH password"
)
parser
.
add_option
(
"-M"
,
"--module-path"
,
dest
=
"module_path"
,
help
=
"path to module library"
,
default
=
C
.
DEFAULT_MODULE_PATH
)
parser
.
add_option
(
'-o'
,
'--override-hosts'
,
dest
=
"override_hosts"
,
default
=
None
,
help
=
"run playbook against these hosts regardless of inventory settings"
)
parser
.
add_option
(
'-T'
,
'--timeout'
,
default
=
C
.
DEFAULT_TIMEOUT
,
type
=
'int'
,
dest
=
'timeout'
,
help
=
"set the SSH timeout in seconds"
)
...
...
@@ -62,6 +64,9 @@ def main(args):
sshpass
=
None
if
options
.
ask_pass
:
sshpass
=
getpass
.
getpass
(
prompt
=
"SSH password: "
)
override_hosts
=
None
if
options
.
override_hosts
:
override_hosts
=
options
.
override_hosts
.
split
(
","
)
# run all playbooks specified on the command line
for
playbook
in
args
:
...
...
@@ -73,7 +78,8 @@ def main(args):
verbose
=
True
,
remote_pass
=
sshpass
,
callbacks
=
callbacks
.
PlaybookCallbacks
(),
timeout
=
options
.
timeout
timeout
=
options
.
timeout
,
override_hosts
=
override_hosts
,
)
try
:
results
=
pb
.
run
()
...
...
lib/ansible/playbook.py
View file @
9df612f0
...
...
@@ -47,24 +47,26 @@ class PlayBook(object):
# *****************************************************
def
__init__
(
self
,
playbook
=
None
,
host_list
=
C
.
DEFAULT_HOST_LIST
,
module_path
=
C
.
DEFAULT_MODULE_PATH
,
forks
=
C
.
DEFAULT_FORKS
,
timeout
=
C
.
DEFAULT_TIMEOUT
,
remote_user
=
C
.
DEFAULT_REMOTE_USER
,
remote_pass
=
C
.
DEFAULT_REMOTE_PASS
,
verbose
=
False
,
callbacks
=
None
):
self
.
host_list
=
host_list
self
.
module_path
=
module_path
self
.
forks
=
forks
self
.
timeout
=
timeout
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
self
.
verbose
=
verbose
self
.
callbacks
=
callbacks
playbook
=
None
,
host_list
=
C
.
DEFAULT_HOST_LIST
,
module_path
=
C
.
DEFAULT_MODULE_PATH
,
forks
=
C
.
DEFAULT_FORKS
,
timeout
=
C
.
DEFAULT_TIMEOUT
,
remote_user
=
C
.
DEFAULT_REMOTE_USER
,
remote_pass
=
C
.
DEFAULT_REMOTE_PASS
,
override_hosts
=
None
,
verbose
=
False
,
callbacks
=
None
):
self
.
host_list
=
host_list
self
.
module_path
=
module_path
self
.
forks
=
forks
self
.
timeout
=
timeout
self
.
remote_user
=
remote_user
self
.
remote_pass
=
remote_pass
self
.
verbose
=
verbose
self
.
callbacks
=
callbacks
self
.
override_hosts
=
override_hosts
self
.
callbacks
.
set_playbook
(
self
)
# store the list of changes/invocations/failure counts
...
...
@@ -83,7 +85,8 @@ class PlayBook(object):
self
.
basedir
=
os
.
path
.
dirname
(
playbook
)
self
.
playbook
=
self
.
_parse_playbook
(
playbook
)
self
.
host_list
,
self
.
groups
=
ansible
.
runner
.
Runner
.
parse_hosts
(
host_list
)
self
.
host_list
,
self
.
groups
=
ansible
.
runner
.
Runner
.
parse_hosts
(
host_list
,
override_hosts
=
self
.
override_hosts
)
# *****************************************************
...
...
@@ -499,7 +502,11 @@ class PlayBook(object):
''' run a list of tasks for a given pattern, in order '''
# get configuration information about the pattern
pattern
=
pg
[
'hosts'
]
pattern
=
pg
.
get
(
'hosts'
,
None
)
if
self
.
override_hosts
:
pattern
=
'all'
if
pattern
is
None
:
raise
errors
.
AnsibleError
(
'hosts declaration is required'
)
vars
=
self
.
_get_vars
(
pg
,
self
.
basedir
)
vars_files
=
pg
.
get
(
'vars_files'
,
{})
...
...
lib/ansible/runner.py
View file @
9df612f0
...
...
@@ -149,9 +149,14 @@ class Runner(object):
# *****************************************************
@classmethod
def
parse_hosts
(
cls
,
host_list
):
def
parse_hosts
(
cls
,
host_list
,
override_hosts
=
None
):
''' parse the host inventory file, returns (hosts, groups) '''
if
override_hosts
is
not
None
:
if
type
(
override_hosts
)
!=
list
:
raise
errors
.
AnsibleError
(
"override hosts must be a list"
)
return
(
override_hosts
,
dict
(
ungrouped
=
override_hosts
))
if
type
(
host_list
)
==
list
:
raise
Exception
(
"function can only be called on inventory files"
)
...
...
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