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

Add function to run playbook on a host #49

Merged
merged 14 commits into from
Jun 23, 2023

Conversation

BelenValdivia
Copy link

@BelenValdivia BelenValdivia commented Jun 6, 2023

Description

Add function to run playbook on a host

Testing

  • Run:

    >>> from wazuh_qa_framework.system.host_manager import HostManager
    >>> hm = HostManager('inventory.yml')
    >>> hm.run_playbook('/home/belen/Repositories/qa-system-framework/test.yml')
    
  • Windows agent
    run playbook windows

  • Linux agent

    run playbook agent

  • Manager

    run playbook manager

@BelenValdivia BelenValdivia requested a review from Rebits June 7, 2023 13:46
Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

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

Good Job. Some changes are required

src/wazuh_qa_framework/system/host_manager.py Show resolved Hide resolved

Args:
playbook_path (str): Playbook path to run.
path (str): The full path of the file/object to get the facts of.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
path (str): The full path of the file/object to get the facts of.
playbook_path (str): The full path of the file/object to get the facts of.

Copy link
Author

Choose a reason for hiding this comment

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

Done in 416a12a

except Exception as e:
raise Exception(f"Run playbook fails due to an unexpected error: {e}")

return runner.rc == 0
Copy link
Member

Choose a reason for hiding this comment

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

Is necessary this return?

Copy link
Author

Choose a reason for hiding this comment

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

I think it's ok to know if the playbook runs successfully. Why do you think it's not necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Because if it fails it should raise an Exception, so the return statement does not provide extra information.
IMHO is better to return the runner object instead to gather stdout, stderr, events, etc

Copy link
Author

Choose a reason for hiding this comment

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

Done 20f7457

src/wazuh_qa_framework/system/host_manager.py Show resolved Hide resolved
except Exception as e:
raise Exception(f"Run playbook fails due to an unexpected error: {e}")

return runner.rc == 0
Copy link
Member

Choose a reason for hiding this comment

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

Because if it fails it should raise an Exception, so the return statement does not provide extra information.
IMHO is better to return the runner object instead to gather stdout, stderr, events, etc

@BelenValdivia
Copy link
Author

  • Added ansible-runner as a dependency in project.toml
    image

Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

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

LGTM

@Rebits Rebits merged commit dd1fdd9 into system-refactor Jun 23, 2023
@BelenValdivia BelenValdivia deleted the 37-run-ansible-playbook branch August 3, 2023 12:25
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.

HostManager: Include method to run ansible playbook directly to a host
2 participants