---
-- hosts: jenkins
- user: admin
- sudo: true
+- hosts: jenkins_master
+ user: cm
+ become: true
roles:
- ansible-jenkins
vars:
# Safe-restart Jenkins
- name: restart jenkins
- sudo: yes
command: java -jar {{ jenkins.cli_dest }} -s http://localhost:{{ port }} safe-restart
- name: restart nginx
- sudo: yes
- action: service name=nginx state=restarted
- #command: service nginx restart
+ service:
+ name: nginx
+ state: restarted
group: jenkins
mode: 0644
-- name: Tell SELinux that we should allow Nginx to talk to Jenkins
- seboolean: name=httpd_can_network_connect state=yes persistent=yes
- when: ansible_pkg_mgr == "yum"
-
-- name: copy JJB config file to {{ jenkins_jobs }}
+- name: "copy JJB config file to {{ jenkins_jobs }}"
synchronize:
src: jobs/jenkins-job-builder
dest: '{{ jenkins_jobs }}'
owner: no
group: no
-- name: ensure correct ownership of {{ jenkins_jobs }}
+- name: "ensure correct ownership of {{ jenkins_jobs }}"
file:
path: '{{ jenkins_jobs }}'
state: directory
---
-
-- name: epel-release install
- yum: name=epel-release
- state=present
- when: ansible_pkg_mgr == "yum"
-
-- name: Install RPM dependencies
- yum: name={{ item }} state=installed
- with_items: jenkins.{{ ansible_pkg_mgr }}.dependencies
- when: ansible_pkg_mgr == "yum"
-
- name: Install DEB dependencies
- apt: name={{ item }} state=installed
- with_items: jenkins.{{ ansible_pkg_mgr }}.dependencies
- when: ansible_pkg_mgr == "apt"
+ apt:
+ name: "{{ item }}"
+ state: installed
+ with_items: "{{ jenkins.dependencies }}"
- include: nginx.yml
-- name: Install Jenkins with Yum
- yum: name=jenkins state=present
+- name: Install Jenkins
+ apt:
+ name: jenkins
+ state: present
register: jenkins_install
- when: ansible_pkg_mgr == "yum"
-
-- name: Install Jenkins with Apt
- apt: name=jenkins state=present
- register: jenkins_install
- when: ansible_pkg_mgr == "apt"
- include: config.yml
---
- name: ensure sites-available for nginx
- file: path=/etc/nginx/sites-available state=directory
+ file:
+ path: /etc/nginx/sites-available
+ state: directory
- name: ensure sites-enable for nginx
- file: path=/etc/nginx/sites-enabled state=directory
+ file:
+ path: /etc/nginx/sites-enabled
+ state: directory
- name: remove default nginx site
- action: file path=/etc/nginx/sites-enabled/default state=absent
+ file:
+ path: /etc/nginx/sites-enabled/default
+ state: absent
- name: write nginx.conf
- action: template src=../templates/nginx.conf dest=/etc/nginx/nginx.conf
+ template:
+ src: templates/nginx.conf
+ dest: /etc/nginx/nginx.conf
- name: write jenkins SSL public cert
copy:
when: ansible_pkg_mgr == 'apt'
- name: create nginx site config
- action: template src=../templates/jenkins.conf dest=/etc/nginx/sites-available/jenkins.conf
+ template:
+ src: templates/jenkins.conf
+ dest: /etc/nginx/sites-available/jenkins.conf
notify:
- restart nginx
- name: link nginx config
- action: file src=/etc/nginx/sites-available/jenkins.conf dest=/etc/nginx/sites-enabled/jenkins.conf state=link
+ file:
+ src: /etc/nginx/sites-available/jenkins.conf
+ dest: /etc/nginx/sites-enabled/jenkins.conf
+ state: link
- name: Enable Nginx service
- service: name=nginx enabled=yes state=started
+ service:
+ name: nginx
+ enabled: yes
+ state: started
---
-
-# Yum
-
-- name: Install python-devel
- yum: name=python-devel state=present
- when: ansible_pkg_mgr == "yum"
-
-- name: Install python-pycurl
- yum: name=python-pycurl state=present
- when: ansible_pkg_mgr == "yum"
-
-- name: Add Jenkins GPG Key
- rpm_key: state=present key=https://jenkins-ci.org/redhat/jenkins-ci.org.key
- when: ansible_pkg_mgr == "yum"
-
-- name: Create the repo file for Jenkins
- copy: src=jenkins.repo
- dest=/etc/yum.repos.d/
- owner=root
- group=root
- mode=0644
- when: ansible_pkg_mgr == "yum"
-
-# Apt
-
- name: Add Jenkins GPG Key
apt_key:
url: "https://jenkins-ci.org/debian/jenkins-ci.org.key"
state: present
- when: ansible_pkg_mgr == "apt"
- name: Add the jenkins repo
apt_repository:
repo: 'deb http://pkg.jenkins-ci.org/debian binary/'
state: present
update_cache: true
- when: ansible_pkg_mgr == "apt"
jenkins_lib: /var/lib/jenkins
jenkins_jobs: '{{ jenkins_lib }}/jobs'
jenkins:
- yum:
- #repo: 'deb http://pkg.jenkins-ci.org/debian binary/' # Jenkins repository
- dependencies: # Jenkins dependencies
- #- 'openjdk-7-jre'
- - 'java-1.7.0-openjdk'
- - 'git'
- - 'curl'
- - 'nginx'
- config_file: '/etc/sysconfig/jenkins'
- apt:
- dependencies: # Jenkins dependencies
- - 'git'
- - 'curl'
- - 'nginx'
- config_file: '/etc/default/jenkins'
+ dependencies: # Jenkins dependencies
+ - 'git'
+ - 'curl'
+ - 'nginx'
+ - 'default-jdk'
+ config_file: '/etc/default/jenkins'
cli_dest: '{{ jenkins_dest }}/jenkins-cli.jar' # Jenkins CLI destination
updates_dest: '{{ jenkins_dest }}/updates_jenkins.json' # Jenkins updates file