This guide installs Jenkins from the official Jenkins apt repository and enables the service.
- name: Deploy Jenkins
hosts: jenkins
become: true
tasks:
- name: Install dependencies
ansible.builtin.apt:
update_cache: true
name:
- curl
- fontconfig
- openjdk-21-jre
state: present
- name: Ensure apt keyring directory exists
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: "0755"
- name: Download Jenkins apt key
ansible.builtin.get_url:
url: https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
dest: /etc/apt/keyrings/jenkins-keyring.asc
mode: "0644"
- name: Add Jenkins apt repository
ansible.builtin.copy:
dest: /etc/apt/sources.list.d/jenkins.list
mode: "0644"
content: |
deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/
- name: Install Jenkins
ansible.builtin.apt:
update_cache: true
name: jenkins
state: present
- name: Enable and start Jenkins
ansible.builtin.systemd:
name: jenkins
enabled: true
state: started
ansible-playbook -i inventory.ini jenkins-install.yml