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 ansible playbook to clean nodes in inventory #104

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cailafinn
Copy link
Collaborator

@cailafinn cailafinn commented Jan 14, 2025

Cleans the jenkins workspace stored in docker containers for a set of nodes defined in the inventory.txt file.

Provides tags to determine which of the pipeline's workspaces should be cleaned. Otherwise, does them all.

To Test:

  1. Pick a node and run the script against a nightly tag (probably least intrusive since they're always clean), following the instructions in the documentation.

Fixes #103

@cailafinn cailafinn marked this pull request as ready for review January 14, 2025 15:40
@warunawickramasingha warunawickramasingha self-assigned this Jan 22, 2025
@@ -0,0 +1,36 @@
- name: Playbook to clean jenkins agents by removing workspaces.
hosts: all

Copy link
Contributor

@warunawickramasingha warunawickramasingha Feb 12, 2025

Choose a reason for hiding this comment

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

I think it will be useful if there is an additional section to log the directories that would be deleted via this. For example, having some logging tasks that will always run regardless of the tag specified would list the existing directories along with their sizes.

The same can be used to check the existing dirs before deleting as well(By first running without giving any tags).

Suggested change
- name: Collect existing dir names and their sizes
community.docker.docker_container_exec:
container: "{{ agent_name }}"
command: bash -l -c "du -sh * | awk '{print $1, $2}'"
chdir: "/jenkins_workdir/workspace"
register: dirs_and_sizes
become: yes
tags: [always]
- name: Log existing dirs with their sizes
debug:
msg: "{{ dirs_and_sizes.stdout_lines }}"
tags: [always]

Copy link
Contributor

@warunawickramasingha warunawickramasingha left a comment

Choose a reason for hiding this comment

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

Requesting a small change to log the directories before cleaning. Otherwise the changes look good.

Copy link
Contributor

@warunawickramasingha warunawickramasingha left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, tested this on isis-cloud-linux-b-5 node(made the node temporarily offline) with nightly tag and it worked as expected.

Node is back online now and I am happy to approve!

@sf1919 sf1919 self-assigned this Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

Create an Ansible Script to Clean Jenkins Node Workspaces
3 participants