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
af97e732
Commit
af97e732
authored
Apr 04, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated ansible-playbook to use display, fixed issues breaking display class
parent
e6e69c08
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
34 deletions
+25
-34
v2/ansible/executor/playbook_executor.py
+1
-1
v2/ansible/playbook/play.py
+1
-1
v2/ansible/utils/display.py
+4
-3
v2/bin/ansible-playbook
+19
-29
No files found.
v2/ansible/executor/playbook_executor.py
View file @
af97e732
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
# Make coding more python3-ish
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
__future__
import
(
absolute_import
,
division
)
__metaclass__
=
type
__metaclass__
=
type
import
signal
import
signal
...
...
v2/ansible/playbook/play.py
View file @
af97e732
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
# Make coding more python3-ish
from
__future__
import
(
absolute_import
,
division
,
print_function
)
from
__future__
import
(
absolute_import
,
division
)
__metaclass__
=
type
__metaclass__
=
type
from
ansible.errors
import
AnsibleError
,
AnsibleParserError
from
ansible.errors
import
AnsibleError
,
AnsibleParserError
...
...
v2/ansible/utils/display.py
View file @
af97e732
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
# FIXME: copied mostly from old code, needs py3 improvements
# FIXME: copied mostly from old code, needs py3 improvements
import
textwrap
import
textwrap
import
sys
from
ansible
import
constants
as
C
from
ansible
import
constants
as
C
from
ansible.errors
import
*
from
ansible.errors
import
*
...
@@ -97,15 +98,15 @@ class Display:
...
@@ -97,15 +98,15 @@ class Display:
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
deprecations
:
if
new_msg
not
in
deprecations
:
self
.
_
display
(
new_msg
,
color
=
'purple'
,
stderr
=
True
)
self
.
display
(
new_msg
,
color
=
'purple'
,
stderr
=
True
)
self
.
_deprecations
[
new_msg
]
=
1
self
.
_deprecations
[
new_msg
]
=
1
def
warning
(
self
,
msg
):
def
warning
(
self
,
msg
):
new_msg
=
"
\n
[WARNING]:
%
s"
%
msg
new_msg
=
"
\n
[WARNING]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
warns
:
if
new_msg
not
in
self
.
_
warns
:
self
.
_
display
(
new_msg
,
color
=
'bright purple'
,
stderr
=
True
)
self
.
display
(
new_msg
,
color
=
'bright purple'
,
stderr
=
True
)
self
.
_warns
[
new_msg
]
=
1
self
.
_warns
[
new_msg
]
=
1
def
system_warning
(
self
,
msg
):
def
system_warning
(
self
,
msg
):
...
...
v2/bin/ansible-playbook
View file @
af97e732
...
@@ -21,13 +21,9 @@ from ansible.utils.vars import combine_vars
...
@@ -21,13 +21,9 @@ from ansible.utils.vars import combine_vars
from
ansible.utils.vault
import
read_vault_file
from
ansible.utils.vault
import
read_vault_file
from
ansible.vars
import
VariableManager
from
ansible.vars
import
VariableManager
# Implement an ansible.utils.warning() function later
def
warning
(
*
args
,
**
kwargs
):
print
(
*
args
,
**
kwargs
)
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
def
main
(
args
):
def
main
(
display
,
args
):
''' run ansible-playbook operations '''
''' run ansible-playbook operations '''
# create parser for CLI options
# create parser for CLI options
...
@@ -122,16 +118,14 @@ def main(args):
...
@@ -122,16 +118,14 @@ def main(args):
no_hosts
=
False
no_hosts
=
False
if
len
(
inventory
.
list_hosts
())
==
0
:
if
len
(
inventory
.
list_hosts
())
==
0
:
# Empty inventory
# Empty inventory
warning
(
"provided hosts list is empty, only localhost is available"
)
display
.
warning
(
"provided hosts list is empty, only localhost is available"
)
no_hosts
=
True
no_hosts
=
True
inventory
.
subset
(
options
.
subset
)
inventory
.
subset
(
options
.
subset
)
if
len
(
inventory
.
list_hosts
())
==
0
and
no_hosts
is
False
:
if
len
(
inventory
.
list_hosts
())
==
0
and
no_hosts
is
False
:
# Invalid limit
# Invalid limit
raise
errors
.
AnsibleError
(
"Specified --limit does not match any hosts"
)
raise
errors
.
AnsibleError
(
"Specified --limit does not match any hosts"
)
# create the playbook executor, which manages running the plays
# create the playbook executor, which manages running the plays via a task queue manager
# via a task queue manager
display
=
Display
()
pbex
=
PlaybookExecutor
(
playbooks
=
args
,
inventory
=
inventory
,
variable_manager
=
variable_manager
,
loader
=
loader
,
display
=
display
,
options
=
options
)
pbex
=
PlaybookExecutor
(
playbooks
=
args
,
inventory
=
inventory
,
variable_manager
=
variable_manager
,
loader
=
loader
,
display
=
display
,
options
=
options
)
results
=
pbex
.
run
()
results
=
pbex
.
run
()
...
@@ -139,38 +133,34 @@ def main(args):
...
@@ -139,38 +133,34 @@ def main(args):
if
isinstance
(
results
,
list
):
if
isinstance
(
results
,
list
):
for
p
in
results
:
for
p
in
results
:
print
(
''
)
display
.
display
(
'
\n
playbook:
%
s
\n
'
%
p
[
'playbook'
])
print
(
'playbook:
%
s'
%
p
[
'playbook'
])
print
(
''
)
for
play
in
p
[
'plays'
]:
for
play
in
p
[
'plays'
]:
if
options
.
listhosts
:
if
options
.
listhosts
:
print
(
"
\n
%
s (
%
s): host count=
%
d"
%
(
play
[
'name'
],
play
[
'pattern'
],
len
(
play
[
'hosts'
])))
display
.
display
(
"
\n
%
s (
%
s): host count=
%
d"
%
(
play
[
'name'
],
play
[
'pattern'
],
len
(
play
[
'hosts'
])))
for
host
in
play
[
'hosts'
]:
for
host
in
play
[
'hosts'
]:
print
(
"
%
s"
%
host
)
display
.
display
(
"
%
s"
%
host
)
if
options
.
listtasks
:
#TODO: do we want to display block info?
if
options
.
listtasks
:
#TODO: do we want to display block info?
print
(
"
\n
%
s: task count=
%
d"
%
(
play
[
'name'
],
len
(
play
[
'tasks'
])
))
display
.
display
(
"
\n
%
s"
%
(
play
[
'name'
]
))
for
task
in
play
[
'tasks'
]:
for
task
in
play
[
'tasks'
]:
print
(
"
%
s"
%
task
)
display
.
display
(
"
%
s"
%
task
)
if
options
.
listtags
:
if
options
.
listtags
:
#TODO: fix once we figure out block handling above
print
(
"
\n
%
s: tags count=
%
d"
%
(
play
[
'name'
],
len
(
play
[
'tags'
])))
display
.
display
(
"
\n
%
s: tags count=
%
d"
%
(
play
[
'name'
],
len
(
play
[
'tags'
])))
for
tag
in
play
[
'tags'
]:
for
tag
in
play
[
'tags'
]:
print
(
"
%
s"
%
tag
)
display
.
display
(
"
%
s"
%
tag
)
return
0
else
:
else
:
return
results
return
results
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
#display(" ", log_only=True)
#display(" ".join(sys.argv), log_only=True)
display
=
Display
()
#display(" ", log_only=True)
display
.
display
(
" "
.
join
(
sys
.
argv
),
log_only
=
True
)
try
:
try
:
sys
.
exit
(
main
(
sys
.
argv
[
1
:]))
sys
.
exit
(
main
(
display
,
sys
.
argv
[
1
:]))
except
AnsibleError
as
e
:
except
AnsibleError
as
e
:
#display("ERROR: %s" % e, color='red', stderr=True)
display
.
display
(
"[ERROR]:
%
s"
%
e
,
color
=
'red'
,
stderr
=
True
)
print
(
e
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
#display("ERROR: interrupted", color='red', stderr=True)
display
.
display
(
"[ERROR]: interrupted"
,
color
=
'red'
,
stderr
=
True
)
print
(
"keyboard interrupt"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
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