---

# Usually, we only install Jenkins and let it live its life,
# so if it seems to be already installed, we skip this task.
- name: Check if /var/lib/jenkins exists
  stat:
    path: "{{ jenkins_home }}"
  register: result
- name: No going further if jenkinsonlyinstall is set and Jenkins is already installed
  set_fact:
    gogogo: "{{ jenkins_installonly is undefined or jenkins_installonly == False or result.stat.isdir is undefined or result.stat.isdir == False }}"

- name: Warning about confidentiality
  pause:
    prompt: "Warning: this role will manage and display a lot of passwords and keys readable through the Ansible log and the process infos on each host. Sorry..."
    seconds: 1  # TODO: 10
  when: gogogo


# Pre-check
- include_tasks: roles/jenkins-php-v1/tasks/00_precheck.yml
  when: gogogo

# Install Jenkins via the upstream repository
- include_tasks: roles/jenkins-php-v1/tasks/10_jenkins-repository.yml
  when: gogogo

- include_tasks: roles/jenkins-php-v1/tasks/20_install-plugins.yml
  when: gogogo

# At the moment, groups or roles are kinda overkill
# (but it probably will get back on us at the end...)
- include_tasks: roles/jenkins-php-v1/tasks/30_users.yml
  when: gogogo

# Big configuration step : ACL, SSH keys aka. credentials, etc.
- include_tasks: roles/jenkins-php-v1/tasks/40_configure-jenkins.yml
  when: gogogo

- include_tasks: roles/jenkins-php-v1/tasks/50_create-jobs.yml
  when: gogogo

- include_tasks: roles/jenkins-php-v1/tasks/60_install-nginx-proxy.yml
  when: gogogo