---
- name: Adding Jenkins user
  user: name=jenkins groups=sudo,shadow shell=/bin/bash append=yes generate_ssh_key=yes ssh_key_file=.ssh/id_rsa

- name: Adding Jenkins user to sudoers
  lineinfile: dest=/etc/sudoers state=present regexp='^%jenkins' line='%jenkins ALL=(ALL) NOPASSWD:ALL' validate='visudo -cf %s'

- name: Set JAVA_HOME
  lineinfile: dest=/home/jenkins/.bashrc line="{{item}}"
  with_items:
  - export JAVA_HOME=/usr/lib/jvm/java-8-oracle

- name: Add the Jenkins APT repository key
  apt_key: url=http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key state=present

- name: Add the Jenkins APT repository
  apt_repository: repo="deb http://pkg.jenkins-ci.org/debian binary/" state=present

- name: Install Jenkins
  apt: name={{item}} state=latest update_cache=yes
  with_items:
  - jenkins

- name: Configure Jenkins
  template: src=jenkins.j2 dest=/etc/default/jenkins

---
- name: Adding Jenkins user
  user: name=jenkins groups=sudo,shadow shell=/bin/bash append=yes generate_ssh_key=yes ssh_key_file=.ssh/id_rsa

- name: Adding Jenkins user to sudoers
  lineinfile: dest=/etc/sudoers state=present regexp='^%jenkins' line='%jenkins ALL=(ALL) NOPASSWD:ALL' validate='visudo -cf %s'

- name: Set JAVA_HOME
  lineinfile: dest=/home/jenkins/.bashrc line="{{item}}"
  with_items:
  - export JAVA_HOME=/usr/lib/jvm/java-9-oracle

- name: Add the Jenkins APT repository key
  apt_key: url=http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key state=present

- name: Add the Jenkins APT repository
  apt_repository: repo="deb http://pkg.jenkins-ci.org/debian binary/" state=present

- name: Install Jenkins
  apt: name={{item}} state=latest update_cache=yes
  with_items:
  - jenkins

- name: Configure Jenkins
  template: src=jenkins.j2 dest=/etc/default/jenkins

Upgrade jenkins to use jdk 1.9
Upgrade jenkins to use jdk 1.9
