-
Notifications
You must be signed in to change notification settings - Fork 13
WIP-DO NOT MERGE: Add json output #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| [ssh_connection] | ||
| pipelining = True | ||
| pipelining = True | ||
| [defaults] | ||
| stdout_callback = json | ||
| callback_whitelist = json | ||
| json_indent = 4 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,8 +289,12 @@ def ansible_command_sequence(configure_data_ansible, base_project, sequence, ver | |
| ansible_cmd_seq.append({'cmd': ssh_share}) | ||
| original_env = dict(os.environ) | ||
| original_env['ANSIBLE_PIPELINING'] = 'True' | ||
| if profile: | ||
| original_env['ANSIBLE_CALLBACK_WHITELIST'] = 'ansible.posix.profile_tasks' | ||
| original_env['ANSIBLE_CALLBACKS_ENABLED'] = 'json' | ||
| original_env['ANSIBLE_LOAD_CALLBACK_PLUGINS'] = '1' | ||
| original_env['ANSIBLE_STDOUT_CALLBACK'] = 'json' | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the ones to use in order to have json output
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. master what happend with the profile code? if we decided to include the json format |
||
| #original_env['ANSIBLE_CONFIG'] = os.path.join(base_project, 'ansible.cfg') | ||
| #if profile: | ||
| #original_env['ANSIBLE_CALLBACK_WHITELIST'] = 'json' | ||
| if 'roles_path' in configure_data_ansible: | ||
| original_env['ANSIBLE_ROLES_PATH'] = configure_data_ansible['roles_path'] | ||
|
|
||
|
|
@@ -345,18 +349,15 @@ def cmd_ansible(configure_data, base_project, dryrun, verbose, destroy=False, pr | |
| return Status("ok") | ||
|
|
||
| inventory = os.path.join(base_project, 'terraform', configure_data['provider'], 'inventory.yaml') | ||
| ansible_cmd_seq = ansible_command_sequence(configure_data['ansible'], base_project, sequence, verbose, inventory, profile) | ||
| ansible_cmd_seq = ansible_command_sequence(configure_data['ansible'], base_project, sequence, False, inventory, profile) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the verbose output, not sure if it impacts json output in any way, I think not
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not but will afect this pr already merge os-autoinst/os-autoinst-distri-opensuse#18787 |
||
|
|
||
| for command in ansible_cmd_seq: | ||
| if dryrun: | ||
| print(' '.join(command['cmd'])) | ||
| else: | ||
| ret, out = lib.process_manager.subprocess_run(**command) | ||
| log.debug("Ansible process return ret:%d", ret) | ||
| if ret == 0: | ||
| for out_line in out: | ||
| log.debug("> %s", out_line) | ||
| else: | ||
| if ret != 0: | ||
| log.error("command:%s returned non zero %d", command, ret) | ||
| return Status(ret) | ||
| return Status("ok") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| All tools needed to manage external executable and processes | ||
| ''' | ||
|
|
||
| import sys | ||
| import subprocess | ||
| import logging | ||
|
|
||
|
|
@@ -31,6 +32,11 @@ def subprocess_run(cmd, env=None): | |
| return (proc.returncode, []) | ||
| stdout = [line.decode("utf-8") for line in proc.stdout.splitlines()] | ||
|
|
||
| print(f"OUTPUT START FOR COMMAND: {cmd}") | ||
| sys.stdout.flush() | ||
| for line in stdout: | ||
| log.debug('OUTPUT: %s', line) | ||
| print(line) | ||
| sys.stdout.flush() | ||
| print(f"OUTPUT END FOR COMMAND: {cmd}") | ||
| sys.stdout.flush() | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part needed to change, otherwise the logging messages were mixed with the json output. This was strange and shouldn't happen, since this whole execution is serial and not parallel, but I think that the This was fixed by using sys.stdout.flush() after each line printing, to send it to stdout immediatelly, so... I was probably right? Dunno. But it works.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice master!! |
||
| return (0, stdout) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes do not matter, as the cfg file is not used. Look at the description to use it in the future