Skip to content

Instantly share code, notes, and snippets.

@wate
Last active Oct 31, 2017
Embed
What would you like to do?
「ansibleを使用してjenkinsをインストールする方法」にインスパイアされて書いてみた
# ネタ元
# ansibleを使用してjenkinsをインストールする方法
# https://awsbloglink.wordpress.com/2017/10/31/ansible%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6jenkins%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/
- name: setup jenkins
hosts: all
become: yes
handlers:
- name: restart jenkins
systemd:
name: jenkins
state: restarted
vars:
jenkins_admin_user: admin
jenkins_admin_password:
jenkins_home: /var/lib/jenkins
jenkins_java_options: "-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false"
jenkins_plugins:
- cloudbees-folder
- antisamy-markup-formatter
- build-timeout
- credentials-binding
- timestamper
- ws-cleanup
- ant
- gradle
- workflow-aggregator
- github-branch-source
- pipeline-github-lib
- pipeline-stage-view
- build-pipeline-plugin
- git
- subversion
- ssh-slaves
- matrix-auth
- pam-auth
- ldap
- email-ext
- mailer
tasks:
- name: install openjdk
yum:
name: java-1.8.0-openjdk
- name: add jenkins yum repository
yum_repository:
name: jenkins
description: Jenkins-stable
file: jenkins
baseurl: http://pkg.jenkins.io/redhat-stable
gpgcheck: yes
- name: import gpg key
rpm_key:
key: https://jenkins-ci.org/redhat/jenkins-ci.org.key
- name: install jenkins
yum:
name: jenkins
- name: replace jenkins java options
replace:
path: /etc/sysconfig/jenkins
regexp: '^JENKINS_JAVA_OPTIONS=.*'
replace: 'JENKINS_JAVA_OPTIONS="{{ jenkins_java_options }}"'
notify: restart jenkins
- name: start jenkins
systemd:
name: jenkins
state: started
enabled: yes
- name: wait for jenkins to start up
wait_for:
host: localhost
port: 8080
state: drained
delay: 30
retries: 5
# - block:
# - name: read initial admin password
# command: cat /var/lib/jenkins/secrets/initialAdminPassword
# register: result
# changed_when: false
# - name: print initial password
# debug:
# msg: "{{ result.stdout }}"
# - name: set variable jenkins admin password
# set_fact:
# jenkins_admin_password: "{{ result.stdout }}"
# when: not jenkins_admin_password
- name: install jenkins plugins
jenkins_plugin:
name: "{{ item }}"
timeout: 300
url_password: "{{ jenkins_admin_password }}"
params:
url_username: "{{ jenkins_admin_user }}"
with_items: "{{ jenkins_plugins }}"
notify: restart jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment