Skip to content
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

WIP-DO NOT MERGE: Add json output #222

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BillAnastasiadis
Copy link
Collaborator

@BillAnastasiadis BillAnastasiadis commented Apr 26, 2024

DO NOT MERGE this is just an example showcasing things that need to be done to use json output for ansible in qe-sap deployment.

IMPORTANT NOTES:

  • The .cfg file changes are not relevant, as the cfg is not used, but rather the output is configured through env variables
  • The cfg is not used anywhere, I believe. This can change if we want to use the ansible.cfg for stuff, by adding
    original_env['ANSIBLE_CONFIG'] = os.path.join(base_project, 'ansible.cfg')

in cmds.py.

EXAMPLE OUTPUT:
https://openqa.suse.de/tests/14152898/logfile?filename=deploy_qesap_ansible-qesap_exec_ansible.log.txt

Just go down some lines, and you'll see the output. Each playbook is another json.

stdout_callback = json
callback_whitelist = json
json_indent = 4
Copy link
Collaborator Author

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

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'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the ones to use in order to have json output

Copy link
Contributor

Choose a reason for hiding this comment

The 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

@@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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

print(line)
sys.stdout.flush()
print(f"OUTPUT END FOR COMMAND: {cmd}")
sys.stdout.flush()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 print commands stacked up instead of being immediately delivered to stdout, so at some point some of the latter logging messages were mixed in.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice master!!

@BillAnastasiadis BillAnastasiadis changed the title WIP-EXAMPLE: Add json output WIP-DO NOT MERGE: Add json output Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants