Add output printing to host-command-run
Change-Id: I50f75f8f8ed200b1c70f834973463c2f7343ed1a
This commit is contained in:
parent
f8575af9c0
commit
847bb8666d
@ -5,3 +5,12 @@
|
|||||||
tasks:
|
tasks:
|
||||||
- name: Run a command
|
- name: Run a command
|
||||||
shell: "{{ host_command_to_run }}"
|
shell: "{{ host_command_to_run }}"
|
||||||
|
register: command_output
|
||||||
|
- name: Print stdout
|
||||||
|
debug:
|
||||||
|
msg: "{{ command_output.stdout }}"
|
||||||
|
when: show_output | bool
|
||||||
|
- name: Print stderr
|
||||||
|
debug:
|
||||||
|
msg: "{{ command_output.stderr }}"
|
||||||
|
when: show_output | bool
|
||||||
|
@ -494,12 +494,15 @@ class SeedHypervisorHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
|
|||||||
group = parser.add_argument_group("Host Command Run")
|
group = parser.add_argument_group("Host Command Run")
|
||||||
group.add_argument("--command", required=True,
|
group.add_argument("--command", required=True,
|
||||||
help="Command to run (required).")
|
help="Command to run (required).")
|
||||||
|
group.add_argument("--show-output", action='store_true',
|
||||||
|
help="Show command output")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.app.LOG.debug("Run command on seed hypervisor host")
|
self.app.LOG.debug("Run command on seed hypervisor host")
|
||||||
extra_vars = {
|
extra_vars = {
|
||||||
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
|
"host_command_to_run": utils.escape_jinja(parsed_args.command),
|
||||||
|
"show_output": parsed_args.show_output}
|
||||||
playbooks = _build_playbook_list("host-command-run")
|
playbooks = _build_playbook_list("host-command-run")
|
||||||
self.run_kayobe_playbooks(parsed_args, playbooks,
|
self.run_kayobe_playbooks(parsed_args, playbooks,
|
||||||
limit="seed-hypervisor",
|
limit="seed-hypervisor",
|
||||||
@ -659,12 +662,15 @@ class SeedHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
|
|||||||
group = parser.add_argument_group("Host Command Run")
|
group = parser.add_argument_group("Host Command Run")
|
||||||
group.add_argument("--command", required=True,
|
group.add_argument("--command", required=True,
|
||||||
help="Command to run (required).")
|
help="Command to run (required).")
|
||||||
|
group.add_argument("--show-output", action='store_true',
|
||||||
|
help="Show command output")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.app.LOG.debug("Run command on seed host")
|
self.app.LOG.debug("Run command on seed host")
|
||||||
extra_vars = {
|
extra_vars = {
|
||||||
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
|
"host_command_to_run": utils.escape_jinja(parsed_args.command),
|
||||||
|
"show_output": parsed_args.show_output}
|
||||||
playbooks = _build_playbook_list("host-command-run")
|
playbooks = _build_playbook_list("host-command-run")
|
||||||
self.run_kayobe_playbooks(parsed_args, playbooks, limit="seed",
|
self.run_kayobe_playbooks(parsed_args, playbooks, limit="seed",
|
||||||
extra_vars=extra_vars)
|
extra_vars=extra_vars)
|
||||||
@ -1018,12 +1024,15 @@ class OvercloudHostCommandRun(KayobeAnsibleMixin, VaultMixin, Command):
|
|||||||
group = parser.add_argument_group("Host Command Run")
|
group = parser.add_argument_group("Host Command Run")
|
||||||
group.add_argument("--command", required=True,
|
group.add_argument("--command", required=True,
|
||||||
help="Command to run (required).")
|
help="Command to run (required).")
|
||||||
|
group.add_argument("--show-output", action='store_true',
|
||||||
|
help="Show command output")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.app.LOG.debug("Run command on overcloud host")
|
self.app.LOG.debug("Run command on overcloud host")
|
||||||
extra_vars = {
|
extra_vars = {
|
||||||
"host_command_to_run": utils.escape_jinja(parsed_args.command)}
|
"host_command_to_run": utils.escape_jinja(parsed_args.command),
|
||||||
|
"show_output": parsed_args.show_output}
|
||||||
playbooks = _build_playbook_list("host-command-run")
|
playbooks = _build_playbook_list("host-command-run")
|
||||||
self.run_kayobe_playbooks(parsed_args, playbooks, limit="overcloud",
|
self.run_kayobe_playbooks(parsed_args, playbooks, limit="overcloud",
|
||||||
extra_vars=extra_vars)
|
extra_vars=extra_vars)
|
||||||
|
@ -342,7 +342,8 @@ class TestCase(unittest.TestCase):
|
|||||||
def test_seed_hypervisor_host_command_run(self, mock_run):
|
def test_seed_hypervisor_host_command_run(self, mock_run):
|
||||||
command = commands.SeedHypervisorHostCommandRun(TestApp(), [])
|
command = commands.SeedHypervisorHostCommandRun(TestApp(), [])
|
||||||
parser = command.get_parser("test")
|
parser = command.get_parser("test")
|
||||||
parsed_args = parser.parse_args(["--command", "ls -a"])
|
parsed_args = parser.parse_args(["--command", "ls -a",
|
||||||
|
"--show-output"])
|
||||||
|
|
||||||
result = command.run(parsed_args)
|
result = command.run(parsed_args)
|
||||||
self.assertEqual(0, result)
|
self.assertEqual(0, result)
|
||||||
@ -356,7 +357,8 @@ class TestCase(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
limit="seed-hypervisor",
|
limit="seed-hypervisor",
|
||||||
extra_vars={
|
extra_vars={
|
||||||
"host_command_to_run": utils.escape_jinja("ls -a")},
|
"host_command_to_run": utils.escape_jinja("ls -a"),
|
||||||
|
"show_output": True}
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
self.assertEqual(expected_calls, mock_run.call_args_list)
|
self.assertEqual(expected_calls, mock_run.call_args_list)
|
||||||
@ -551,7 +553,8 @@ class TestCase(unittest.TestCase):
|
|||||||
def test_seed_host_command_run(self, mock_run):
|
def test_seed_host_command_run(self, mock_run):
|
||||||
command = commands.SeedHostCommandRun(TestApp(), [])
|
command = commands.SeedHostCommandRun(TestApp(), [])
|
||||||
parser = command.get_parser("test")
|
parser = command.get_parser("test")
|
||||||
parsed_args = parser.parse_args(["--command", "ls -a"])
|
parsed_args = parser.parse_args(["--command", "ls -a",
|
||||||
|
"--show-output"])
|
||||||
|
|
||||||
result = command.run(parsed_args)
|
result = command.run(parsed_args)
|
||||||
self.assertEqual(0, result)
|
self.assertEqual(0, result)
|
||||||
@ -565,7 +568,8 @@ class TestCase(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
limit="seed",
|
limit="seed",
|
||||||
extra_vars={
|
extra_vars={
|
||||||
"host_command_to_run": utils.escape_jinja("ls -a")},
|
"host_command_to_run": utils.escape_jinja("ls -a"),
|
||||||
|
"show_output": True}
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
self.assertEqual(expected_calls, mock_run.call_args_list)
|
self.assertEqual(expected_calls, mock_run.call_args_list)
|
||||||
@ -1057,7 +1061,8 @@ class TestCase(unittest.TestCase):
|
|||||||
def test_overcloud_host_command_run(self, mock_run):
|
def test_overcloud_host_command_run(self, mock_run):
|
||||||
command = commands.OvercloudHostCommandRun(TestApp(), [])
|
command = commands.OvercloudHostCommandRun(TestApp(), [])
|
||||||
parser = command.get_parser("test")
|
parser = command.get_parser("test")
|
||||||
parsed_args = parser.parse_args(["--command", "ls -a"])
|
parsed_args = parser.parse_args(["--command", "ls -a",
|
||||||
|
"--show-output"])
|
||||||
|
|
||||||
result = command.run(parsed_args)
|
result = command.run(parsed_args)
|
||||||
self.assertEqual(0, result)
|
self.assertEqual(0, result)
|
||||||
@ -1071,7 +1076,8 @@ class TestCase(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
limit="overcloud",
|
limit="overcloud",
|
||||||
extra_vars={
|
extra_vars={
|
||||||
"host_command_to_run": utils.escape_jinja("ls -a")},
|
"host_command_to_run": utils.escape_jinja("ls -a"),
|
||||||
|
"show_output": True}
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
self.assertEqual(expected_calls, mock_run.call_args_list)
|
self.assertEqual(expected_calls, mock_run.call_args_list)
|
||||||
|
5
releasenotes/notes/cli-show-output-11a257c87502d5a3.yaml
Normal file
5
releasenotes/notes/cli-show-output-11a257c87502d5a3.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The ``kayobe * host command run`` commands now support ``--show-output``
|
||||||
|
which displays both standard output and standard error.
|
Loading…
x
Reference in New Issue
Block a user