---

## TODO: add those URLs or domains to the proxy whitelist
# http://pkg.jenkins-ci.org/.*
# http://mirrors.jenkins.io/.*
# http://jenkins.mirror.isppower.de/.*

- name: Jenkins embedded GPG key is absent
  apt_key:
    id: "D50582E6"
    keyring: /etc/apt/trusted.gpg
    state: absent

- name: Add Jenkins GPG key
  copy:
    src: jenkins.asc
    dest: /etc/apt/trusted.gpg.d/jenkins.asc
    force: yes
    mode: "0644"
    owner: root
    group: root

- name: Add jenkins APT repository
  apt_repository:
    repo: deb http://pkg.jenkins-ci.org/debian-stable binary/
    filename: jenkins
    update_cache: yes

- name: Install Jenkins
  apt:
    name: jenkins

- name: Change Jenkins port
  replace:
    name: /etc/default/jenkins
    regexp: "^HTTP_PORT=.*$"
    replace: "HTTP_PORT=8081"
  notify: Restart Jenkins
