--- # Add Jenkins repository for Debian - name: Install GPG - needed to add the repository key apt: name: - gpg state: present - name: Add Jenkins-stable.io repository key apt_key: id: "150FDE3F7787E7D11EF4E12A9B7D32F2D50582E6" data: "{{ lookup('file', 'jenkins-stable.io.pem') }}" state: present register: tmp - name: New APT sources - commit command: "etckeeper commit 'apt: Jenkins repository key added by Ansible'" when: tmp.changed and etckeeper_installed - name: Check if /etc/apt/sources.list.d/jenkins.list is managed by ansible shell: "grep -ic '# This file is managed by Ansible' /etc/apt/sources.list.d/jenkins.list || true" register: result changed_when: false - name: Config /etc/apt/sources.list.d/jenkins.list file template: src: "{{ item }}" dest: /etc/apt/sources.list.d/jenkins.list owner: root group: root mode: 0644 backup: no force: "{{ result.stdout is defined and result.stdout == '1' }}" # Only manage the file if the header is present with_first_found: - "jenkins.list.{{ ansible_fqdn }}.j2" - "jenkins.list.j2" register: tmp - name: New APT sources - commit command: "etckeeper commit 'apt: Jenkins repository added/changed by Ansible'" when: tmp.changed and etckeeper_installed - name: Update APT cache apt: update_cache: yes when: tmp.changed # Install Jenkins # (note: the Jenkins package doesn't wait for Java to be installed # before trying to launch itself, so we install them separately) # (note2: in case we go back downloading the .war, here is a command to # verify it: jarsigner -verbose -certs -verify /tmp/jenkins.war - name: Install Java apt: name: - default-jdk state: present - name: Install Jenkins package apt: name: - jenkins state: present register: result - name: Loop until Jenkins is available get_url: url: "http://localhost:8080/login" dest: "/dev/null" force: True register: tmp until: tmp.status_code is defined and tmp.status_code == 200 or result.changed == False retries: 10 delay: 5 changed_when: False