Created
July 3, 2015 05:43
-
-
Save ownport/79dd3b754926e237bfa7 to your computer and use it in GitHub Desktop.
ansible: jenkins-swarm client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You first need to install the Swarm plugin as mentioned https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin. | |
Then you can proceed with the client installation. | |
First create the jenkins slave working directory. | |
- name: Create Jenkins slave directory | |
file: path=${jenkins_home}/jenkins-slave state=directory owner=jenkins | |
Download the Swarm Client. | |
- name: Download Jenkins Swarm Client | |
get_url: dest=${jenkins_home}/swarm-client-1.8-jar-with-dependencies.jar url=http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/1.8/swarm-client-1.8-jar-with-dependencies.jar owner=jenkins | |
When you start the swarm client, it will connect to the master and the master will automatically create a new node for it. | |
There are a couple of parameters to start the client. You still need to provided a login/password in order to authenticate. You obviously want this information to be parameterizable. | |
First we need a script/configuration to start the swarm client at boot time (systemv, upstart or systemd it is up to you). In that script/configuration, you need to add the swarm client run command: | |
java -jar {{jenkins_home}}/swarm-client-1.8-jar-with-dependencies.jar -name {{jenkins_slave_name}} -password {{jenkins_password}} -username {{jenkins_username}} -fsroot {{jenkins_home}}/jenkins-slave -master https://jenkins.trifork.nl -disableSslVerification &> {{jenkins_home}}/swarm-client.log & | |
Then using the template module http://ansible.cc/docs/modules.html#template, to process the script/configuration template (using Jinja2 http://jinja.pocoo.org/docs/) into a file that will be put on a given location. | |
- name: Install swarm client script | |
template: src=templates/jenkins-swarm-client.tmpl dest=/etc/init.d/jenkins-swarm-client mode=0700 | |
The file mode is 700 because we have a login/password in that file, we don’t want people (that can log on the remote computer) to be able to see that. | |
Instead of putting jenkins_username and jenkins_password in vars files, you can prompt for them. | |
vars_prompt: | |
- name: jenkins_username | |
prompt: "What is your jenkins user?" | |
private: no | |
- name: jenkins_password | |
prompt: "What is your jenkins password?" | |
private: yes | |
And then you can verify that they have been set. | |
- fail: msg="Missing parameters!" | |
when_string: $jenkins_username == '' or $jenkins_password == '' | |
You can now start the swarm client using the service module and enable it to start at boot time. | |
- name: Start Jenkins swarm client | |
action: service name=jenkins-swarm-client state=started enabled=yes | |
http://blog.trifork.com/2013/04/02/ansible-example-playbook-to-setup-jenkins-slave/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment