Skip to content

Commit

Permalink
Merge pull request #21 from ehh-why-its-so-hard/implement_lb
Browse files Browse the repository at this point in the history
feat: add jenkins role
  • Loading branch information
daniel1302 authored Nov 5, 2024
2 parents 17f39f8 + c37f695 commit 5f00e9e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
5 changes: 5 additions & 0 deletions roles/java/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Install Required packages
ansible.builtin.apt:
name:
- openjdk-17-jdk
5 changes: 5 additions & 0 deletions roles/jenkins_master/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
jenkins_master_version: '2.452.4'

jenkins_master_with_zfs: false
jenkins_master_zfs_device: /dev/sdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true -Xms6144m -Xmx6144m"
Environment="JENKINS_OPTS=--sessionTimeout=10080 --sessionEviction=259200"
Environment="JENKINS_HOME=/home/jenkins"
TimeoutSec=900
10 changes: 10 additions & 0 deletions roles/jenkins_master/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: "Reload systemd config"
ansible.builtin.systemd:
daemon_reload: "yes"

- name: "Restart jenkins"
ansible.builtin.systemd:
name: jenkins
enabled: true
state: restarted
69 changes: 69 additions & 0 deletions roles/jenkins_master/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
- name: Setup ZFS
ansible.builtin.import_tasks: zfs.yaml
when: jenkins_master_with_zfs

- name: Ensure jenkins home exists
ansible.builtin.file:
path: "{{- item -}}"
state: directory
mode: '0755'
owner: jenkins
group: jenkins
with_items:
- /home/jenkins
- /home/jenkins/jobs

- name: Add an Apt signing key for Jenkins apt repo
ansible.builtin.apt_key:
url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
state: present

- name: Add Jenkins apt repo into sources list
ansible.builtin.apt_repository:
repo: deb https://pkg.jenkins.io/debian-stable binary/
state: present
update_cache: "yes"
filename: jenkins

- name: Install Required packages
ansible.builtin.apt:
name:
- openjdk-17-jdk

- name: Install Jenkins
ansible.builtin.apt:
name:
- "jenkins={{ jenkins_master_version }}"
notify:
- "Reload systemd config"
- "Restart jenkins"


- name: Create a directory if it does not exist
ansible.builtin.file:
path: /etc/systemd/system/jenkins.service.d/
state: directory
mode: '0755'


- name: Copy jenkins.service.d config
ansible.builtin.copy:
src: 'etc/systemd/system/jenkins.service.d/override.conf'
dest: '/etc/systemd/system/jenkins.service.d/override.conf'
owner: 'root'
group: 'root'
mode: "0644"
notify:
- "Reload systemd config"
- "Restart jenkins"

- name: Restart jenkins periodically
become: true
ansible.builtin.cron:
name: "restart jenkins"
minute: "0"
hour: "5" # 5AM UTC
weekday: "1" # monday
user: root
job: "/usr/bin/systemctl restart jenkins.service"
41 changes: 41 additions & 0 deletions roles/jenkins_master/tasks/zfs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: Create pool
ansible.builtin.shell: |
set -o pipefail
zpool create -f -o ashift=12 "jenkins_pool" "{{- jenkins_master_zfs_device -}}";
zfs set atime=off "jenkins_pool";
zfs set compression=zstd "jenkins_pool";
# enable improved extended attributes - keep in inode instead of dir;
zfs set xattr=sa "jenkins_pool";
# reduce amount of metadata (may improve random writes);
zfs set redundant_metadata=most "jenkins_pool";
touch "/.zfs_pool"
args:
executable: /bin/bash
creates: "/.zfs_pool"

- name: Create dataset
ansible.builtin.shell: |
set -o pipefail
mkdir -p "{{- item.mount_point -}}";
zfs create "{{- item.dataset_name -}}";
zfs set atime=off "{{- item.dataset_name -}}";
zfs set compression=zstd "{{- item.dataset_name -}}";
# enable improved extended attributes - keep in inode instead of dir;
zfs set xattr=sa "{{- item.dataset_name -}}";
# reduce amount of metadata (may improve random writes);
zfs set redundant_metadata=most "{{- item.dataset_name -}}";
zfs set mountpoint="{{- item.mount_point -}}" "{{- item.dataset_name -}}";
touch "{{- item.mount_point -}}/.zfs_pool"
args:
executable: /bin/bash
creates: "{{- item.mount_point -}}/.zfs_pool"
with_items:
- dataset_name: "jenkins_pool/home"
mount_point: "/home/jenkins"
- dataset_name: "jenkins_pool/home/jobs"
mount_point: "jenkins_pool/home/jobs"

0 comments on commit 5f00e9e

Please sign in to comment.