{"id":7656,"date":"2013-04-02T14:20:37","date_gmt":"2013-04-02T12:20:37","guid":{"rendered":"https:\/\/blog.trifork.com\/?p=7656"},"modified":"2013-04-02T14:20:37","modified_gmt":"2013-04-02T12:20:37","slug":"ansible-example-playbook-to-setup-jenkins-slave","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/","title":{"rendered":"Ansible &#8211; Example playbook to setup Jenkins slave"},"content":{"rendered":"<p>As mentioned in my <a href=\"https:\/\/blog.trifork.com\/2013\/03\/26\/ansible-next-generation-configuration-management\/\">previous post about Ansible<\/a>, we will now proceed with writing an Ansible playbook. Playbooks are files containing instructions that can be processed by Ansible, they are written in <a href=\"http:\/\/www.yaml.org\">yaml<\/a>. For this blog post I will show you how to create a playbook that will setup a remote computer as a Jenkins slave.<\/p>\n<h2>What do we need?<\/h2>\n<p>We need some components to get a computer execute Jenkins jobs:<\/p>\n<ul>\n<li>JVM 7<\/li>\n<li>A dedicated user that will run the Jenkins agent<\/li>\n<li>Subversion<\/li>\n<li>Maven (with our configuation)<\/li>\n<li>Jenkins <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Swarm+Plugin\" target=\"_blank\" rel=\"noopener\">Swarm Plugin and Client<\/a><\/li>\n<\/ul>\n<h2>Why Jenkins Swarm Plugin<\/h2>\n<p>We use the Swarm Plugin, because it allows a slave to auto-discover a master and join it automatically. We hence don&#8217;t need any actions on the master.<\/p>\n<h2>JDK7<\/h2>\n<p>We now proceed with adding the JDK7 installation task. We will not use any package version (for example dedicate Ubuntu PPA or RedHat\/Fedora repos), we will use the JDK7 archive from oracle.com.<br \/>\nThere multiple steps required:<\/p>\n<ul>\n<li>We need wget to be install. This is needed to download the JDK<\/li>\n<li>To download the JDK you need to accept terms, we can&#8217;t do that in a batch run so we need to wrap a wget call in a shell script to send extra HTTP headers<\/li>\n<li>Set the platform wide JDK links (java and jar executable)<\/li>\n<\/ul>\n<h3>Install wget<\/h3>\n<p>We want to verify that wget is installed on the remote computer and if not install it from the distribution repos. To install packages, there are modules available, <a href=\"http:\/\/ansible.cc\/docs\/modules.html#apt\">yum<\/a> and <a href=\"http:\/\/ansible.cc\/docs\/modules.html#apt\">apt<\/a> (There are others but we will focus on these).<br \/>\nTo be able to run the correct task depending on the ansible_pkg_mgr value we can use only_id:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Install wget package (Debian based)&lt;br&gt;\n    action: apt pkg='wget' state=installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'apt'&quot;&lt;\/p&gt;\n&lt;p&gt;  - name: Install wget package (RedHat based)&lt;br&gt;\n    action: yum name='wget' state=installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'yum'&quot;&lt;br&gt;\n<\/pre><\/p>\n<h3>Download JDK7<\/h3>\n<p>To download JDK7 from oracle.com, we need to accept the terms but we can&#8217;t do that in a batch, so we need to skip that:<\/p>\n<p>Create a script contains the wget call:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n#!\/bin\/bash&lt;\/p&gt;\n&lt;p&gt;wget --no-cookies --header &quot;Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com&quot; http:\/\/download.oracle.com\/otn-pub\/java\/jdk\/7\/$1 -O $1&lt;br&gt;\n<\/pre><\/p>\n<p>The parameter is the archive name.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Copy download JDK7 script&lt;br&gt;\n    copy: src=files\/download-jdk7.sh dest=\/tmp mode=0555&lt;\/p&gt;\n&lt;p&gt;  - name: Download JDK7 (Ubuntu)&lt;br&gt;\n    action: command creates=${jvm_folder}\/jdk1.7.0 chdir=${jvm_folder} \/tmp\/download-jdk7.sh $jdk_archive&lt;br&gt;\n<\/pre><\/p>\n<p>These two tasks copy the script to \/tmp and then execute it. $jdk_archive is a variable containing the archive name, it can be different depending on the distribution and the architecture.<\/p>\n<p>Ansible provide a way to load variable files:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  vars_files:&lt;\/p&gt;\n&lt;p&gt;    - &#x5B; &quot;vars\/defaults.yml&quot; ]&lt;br&gt;\n    - &#x5B; &quot;vars\/$ansible_distribution-$ansible_architecture.yml&quot;, &quot;vars\/$ansible_distribution.yml&quot; ]&lt;br&gt;\n<\/pre><\/p>\n<p>This will load the file vars\/defauts.yml (Note that all these file are written in <a href=\"http:\/\/www.yaml.org\/\">yaml<\/a>) and then look for the file vars\/$ansible_distribution-$ansible_architecture.yml.<br \/>\nThe variables are replaced by the their value on the remote computer voor example on an Ubuntu 32bits on i386 distribution, Ansible will look for the file vars\/Ubuntu-i386.yml. If it doesn&#8217;t find it, it will fallback to vars\/Ubuntu.yml.<\/p>\n<p>Examples, Ubuntu-i386.yml would contain:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n---&lt;br&gt;\njdk_archive: jdk-7-linux-i586.tar.gz&lt;br&gt;\n<\/pre><\/p>\n<p>Fedora-i686.yml would contain:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n---&lt;br&gt;\njdk_archive: jdk-7-linux-i586.rpm&lt;br&gt;\n<\/pre><\/p>\n<h3>Unpack\/Install JDK<\/h3>\n<p>You notice that for Ubuntu we use the tar.gz archive but for Fedora we use an rpm archive. That means the the installation of the JDK will be different depending on the distribution.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Unpack JDK7&lt;br&gt;\n    action: command creates=${jvm_folder}\/jdk1.7.0 chdir=${jvm_folder} tar zxvf ${jvm_folder}\/$jdk_archive --owner=root&lt;br&gt;\n    register: jdk_installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'apt'&quot;&lt;\/p&gt;\n&lt;p&gt;  - name: Install JDK7 RPM package&lt;br&gt;\n    action: command creates=${jvm_folder}\/latest chdir=${jvm_folder} rpm --force -Uvh ${jvm_folder}\/$jdk_archive&lt;br&gt;\n    register: jdk_installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'yum'&quot;&lt;br&gt;\n<\/pre><\/p>\n<p>On ubuntu, we just unpack the downloaded archive but for fedora we install it using rpm.<br \/>\nYou might want to review the condition (only_if) particularly if you use SuSE.<br \/>\njvm_folder is just an extra variable that can be global of per distribution, you need to place if in a vars file.<br \/>\nNote that the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#command\">command<\/a> module take a &#8216;creates&#8217; parameter. It is useful if you don&#8217;t want to rerun the command, the module that the file or directory provided via this parameter exits, if it does it will skip that task.<br \/>\nIn this task, we use register. With register you can store the result of a task into a variable (in this case we called it jdk_installed).<\/p>\n<h3>Set links<\/h3>\n<p>To be able to make the java and jar executables accessible to anybody (particularly our jenkins user) from anywhere, we set symbolic links (actually we just install an alternative).<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Set java link&lt;br&gt;\n    action: command update-alternatives --install \/usr\/bin\/java java ${jvm_folder}\/jdk1.7.0\/bin\/java 1&lt;br&gt;\n    only_if: '${jdk_installed.changed}'&lt;\/p&gt;\n&lt;p&gt;  - name: Set jar link&lt;br&gt;\n    action: command update-alternatives --install \/usr\/bin\/jar jar ${jvm_folder}\/jdk1.7.0\/bin\/jar 1&lt;br&gt;\n    only_if: '${jdk_installed.changed}'&lt;br&gt;\n<\/pre><\/p>\n<p>Here we reuse the stored register, jdk_installed. We can access the changed attribute, if the unpacking\/installation of the JDK did do something then changed will be true and the update-alternatives command will be ran.<\/p>\n<h3>Cleanup<\/h3>\n<p>To keep things clean, you can remove the downloaded archive using the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#file\">file<\/a> module.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Remove JDK7 archive&lt;br&gt;\n    file: path=${jvm_folder}\/$jdk_archive state=absent&lt;br&gt;\n<\/pre><\/p>\n<p>We are done with the JDK.<\/p>\n<p>Obviously you might want to reuse this process in other playbooks. Ansible let you do that.<br \/>\nJust create a file with all this task and include it in a playbook.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n- include: tasks\/jdk7-tasks.yml jvm_folder=${jvm_folder} jdk_archive=${jdk_archive}&lt;br&gt;\n<\/pre><\/p>\n<h2>jenkins user<\/h2>\n<h3>Creation<\/h3>\n<p>With the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#name\">name<\/a> module, the can easily handle users.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Create jenkins user&lt;br&gt;\n    user: name=jenkins comment=&quot;Jenkins slave user&quot; home=${jenkins_home} shell=\/bin\/bash&lt;br&gt;\n<\/pre><\/p>\n<p>The variable jenkins_home can be defined in one of the vars files.<\/p>\n<h3>Password less from Jenkins master<\/h3>\n<p>We first create the .ssh in the jenkins home directory with the correct rights. And then with the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#authorized_key\">authorized_key<\/a> module, we can add the public of the jenkins user on the jenkins master to the authorized keys of the jenkins user (on the new slave). And then we verify that the new authorized_keys file has the correct rights.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Create .ssh folder&lt;br&gt;\n    file: path=${jenkins_home}\/.ssh state=directory mode=0700 owner=jenkins&lt;\/p&gt;\n&lt;p&gt;  - name: Add passwordless connection for jenkins&lt;br&gt;\n    authorized_key: user=jenkins key=&quot;xxxxxxxxxxxxxx jenkins@master&quot;&lt;\/p&gt;\n&lt;p&gt;  - name: Update authorized_keys rights&lt;br&gt;\n    file: path=${jenkins_home}\/.ssh\/authorized_keys state=file mode=0600 owner=jenkins&lt;br&gt;\n<\/pre><\/p>\n<p>If you want jenkins to execute any command as sudo without the need of providing a password (basically updating \/etc\/sudoers), the module <a href=\"http:\/\/ansible.cc\/docs\/modules.html#lineinfile\">lineinfile<\/a> can do that for you.<br \/>\nThat module checks &#8216;regexp&#8217; against &#8216;dest&#8217;, if it matches it doesn&#8217;t do anything if not, it adds &#8216;line&#8217; to &#8216;dest&#8217;.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Tomcat can run any command with no password&lt;br&gt;\n    lineinfile: &quot;line='tomcat ALL=NOPASSWD: ALL' dest=\/etc\/sudoers regexp='^tomcat'&quot;&lt;br&gt;\n<\/pre><\/p>\n<h2>Subversion<\/h2>\n<p>This one is straight forward.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Install subversion package (Debian based)&lt;br&gt;\n    action: apt pkg='subversion' state=installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'apt'&quot;&lt;\/p&gt;\n&lt;p&gt;  - name: Install subversion package (RedHat based)&lt;br&gt;\n    action: yum name='subversion' state=installed&lt;br&gt;\n    only_if: &quot;'$ansible_pkg_mgr' == 'yum'&quot;&lt;br&gt;\n<\/pre><\/p>\n<h2>Maven<\/h2>\n<p>We will put maven under \/opt so we first need to create that directory.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Create \/opt directory&lt;br&gt;\n    file: path=\/opt state=directory&lt;br&gt;\n<\/pre><\/p>\n<p>We then download the maven3 archive, this time it is more simple, we can directly use the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#get_url\">get_url<\/a> module.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Download Maven3&lt;br&gt;\n    get_url: dest=\/opt\/maven3.tar.gz url=http:\/\/apache.proserve.nl\/maven\/maven-3\/3.0.4\/binaries\/apache-maven-3.0.4-bin.tar.gz&lt;br&gt;\n<\/pre><\/p>\n<p>We can then unpack the archive and create a symbolic link to the maven location.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Unpack Maven3&lt;br&gt;\n    action: command creates=\/opt\/maven chdir=\/opt tar zxvf \/opt\/maven3.tar.gz&lt;\/p&gt;\n&lt;p&gt;  - name: Create Maven3 directory link&lt;br&gt;\n    file: path=\/opt\/maven src=\/opt\/apache-maven-3.0.4 state=link&lt;br&gt;\n<\/pre><\/p>\n<p>We use again update-alternatives to make mvn accessible platform wide.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Set mvn link&lt;br&gt;\n    action: command update-alternatives --install \/usr\/bin\/mvn mvn \/opt\/maven\/bin\/mvn 1&lt;br&gt;\n<\/pre><\/p>\n<p>We put in place out settings.xml by creating the .m2 directory on the remote computer and copying a settings.xml (we backup any already existing settings.xml).<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Create .m2 folder&lt;br&gt;\n    file: path=${jenkins_home}\/.m2 state=directory owner=jenkins&lt;\/p&gt;\n&lt;p&gt;  - name: Copy maven configuration&lt;br&gt;\n    copy: src=files\/settings.xml dest=${jenkins_home}\/.m2\/ backup=yes&lt;br&gt;\n<\/pre><\/p>\n<p>Clean things up.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Remove Maven3 archive&lt;br&gt;\n    file: path=\/opt\/maven3.tar.gz state=absent&lt;br&gt;\n<\/pre><\/p>\n<h2>Swarm client<\/h2>\n<p>You first need to install the Swarm plugin as mentioned <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Swarm+Plugin\">here<\/a>.<br \/>\nThen you can proceed with the client installation.<\/p>\n<p>First create the jenkins slave working directory.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Create Jenkins slave directory&lt;br&gt;\n    file: path=${jenkins_home}\/jenkins-slave state=directory owner=jenkins&lt;br&gt;\n<\/pre><\/p>\n<p>Download the Swarm Client.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Download Jenkins Swarm Client&lt;br&gt;\n    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&lt;br&gt;\n<\/pre><\/p>\n<p>When you start the swarm client, it will connect to the master and the master will automatically create a new node for it.<br \/>\nThere 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.<\/p>\n<p>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:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\njava -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 &amp;amp;&amp;gt; {{jenkins_home}}\/swarm-client.log &amp;amp;&lt;br&gt;\n<\/pre><\/p>\n<p>Then using the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#template\">template<\/a> module, to process the script\/configuration template (using <a href=\"http:\/\/jinja.pocoo.org\/docs\/\">Jinja2<\/a>) into a file that will be put on a given location.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Install swarm client script&lt;br&gt;\n    template: src=templates\/jenkins-swarm-client.tmpl dest=\/etc\/init.d\/jenkins-swarm-client mode=0700&lt;br&gt;\n<\/pre><\/p>\n<p>The file mode is 700 because we have a login\/password in that file, we don&#8217;t want people (that can log on the remote computer) to be able to see that.<\/p>\n<p>Instead of putting jenkins_username and jenkins_password in vars files, you can prompt for them.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  vars_prompt:&lt;\/p&gt;\n&lt;p&gt;    - name: jenkins_username&lt;br&gt;\n      prompt: &quot;What is your jenkins user?&quot;&lt;br&gt;\n      private: no&lt;br&gt;\n    - name: jenkins_password&lt;br&gt;\n      prompt: &quot;What is your jenkins password?&quot;&lt;br&gt;\n      private: yes&lt;br&gt;\n<\/pre><\/p>\n<p>And then you can verify that they have been set.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - fail: msg=&quot;Missing parameters!&quot;&lt;br&gt;\n    when_string: $jenkins_username == '' or $jenkins_password == ''&lt;br&gt;\n<\/pre><\/p>\n<p>You can now start the swarm client using the <a href=\"http:\/\/ansible.cc\/docs\/modules.html#service\">service<\/a> module and enable it to start at boot time.<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n  - name: Start Jenkins swarm client&lt;br&gt;\n    action: service name=jenkins-swarm-client state=started enabled=yes&lt;br&gt;\n<\/pre><\/p>\n<h2>Run it!<\/h2>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\nansible-playbook jenkins.yml --extra-vars &quot;host=myhost user=myuser&quot; --ask-sudo-pass&lt;br&gt;\n<\/pre><\/p>\n<p>By passing &#8216;&#8211;ask-sudo-pass&#8217;, you tell Ansible that &#8216;myuser&#8217; requires a password to be typed in order to be able to run the tasks in the playbook.<br \/>\n&#8216;&#8211;extra-vars&#8217; will pass on a list of viriables to the playbook. The begining of the playbook will look like this:<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;br&gt;\n---&lt;\/p&gt;\n&lt;p&gt;- hosts: $host&lt;br&gt;\n  user: $user&lt;br&gt;\n  sudo: yes&lt;\/p&gt;\n&lt;p&gt;<\/pre><\/p>\n<p>&#8216;sudo: yes&#8217; tells Ansible to run all tasks as root but it acquires the privileges via sudo.<br \/>\nYou can also use &#8216;sudo_user: admin&#8217;, if you want Ansible to run the command to sudo to admin instead of root.<br \/>\nNote that if you don&#8217;t need facts, you can add &#8216;gather_facts: no&#8217;, this will spend up the playbook execution but that requires that you know everything you need about the remote computer.<\/p>\n<h2>Conclusion<\/h2>\n<p>The playbook is ready. You can now easily add new nodes for new Jenkins slaves thanks to Ansible.<\/p>\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bit.ly\/3BAo305\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\" alt=\"\" class=\"wp-image-20303\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-300x75.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-768x192.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1536x384.png 1536w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-2048x512.png 2048w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1920x480.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>As mentioned in my previous post about Ansible, we will now proceed with writing an Ansible playbook. Playbooks are files containing instructions that can be processed by Ansible, they are written in yaml. For this blog post I will show you how to create a playbook that will setup a remote computer as a Jenkins [&hellip;]<\/p>\n","protected":false},"author":83,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[88,10,124],"tags":[332,115,220,86,89,334],"class_list":["post-7656","post","type-post","status-publish","format-standard","hentry","category-devops","category-development","category-system-administration","tag-ansible","tag-cloud","tag-configuration-management","tag-devops","tag-jenkins","tag-playbook"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ansible - Example playbook to setup Jenkins slave - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ansible - Example playbook to setup Jenkins slave - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"As mentioned in my previous post about Ansible, we will now proceed with writing an Ansible playbook. Playbooks are files containing instructions that can be processed by Ansible, they are written in yaml. For this blog post I will show you how to create a playbook that will setup a remote computer as a Jenkins [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-02T12:20:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\" \/>\n<meta name=\"author\" content=\"Mohamed El Moussaoui\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohamed El Moussaoui\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/\",\"url\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/\",\"name\":\"Ansible - Example playbook to setup Jenkins slave - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\",\"datePublished\":\"2013-04-02T12:20:37+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage\",\"url\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\",\"contentUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ansible &#8211; Example playbook to setup Jenkins slave\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972\",\"name\":\"Mohamed El Moussaoui\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g\",\"caption\":\"Mohamed El Moussaoui\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/mohamedm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ansible - Example playbook to setup Jenkins slave - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/","og_locale":"en_US","og_type":"article","og_title":"Ansible - Example playbook to setup Jenkins slave - Trifork Blog","og_description":"As mentioned in my previous post about Ansible, we will now proceed with writing an Ansible playbook. Playbooks are files containing instructions that can be processed by Ansible, they are written in yaml. For this blog post I will show you how to create a playbook that will setup a remote computer as a Jenkins [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/","og_site_name":"Trifork Blog","article_published_time":"2013-04-02T12:20:37+00:00","og_image":[{"url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png","type":"","width":"","height":""}],"author":"Mohamed El Moussaoui","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Mohamed El Moussaoui","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/","url":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/","name":"Ansible - Example playbook to setup Jenkins slave - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage"},"image":{"@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage"},"thumbnailUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png","datePublished":"2013-04-02T12:20:37+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#primaryimage","url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png","contentUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png"},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/ansible-example-playbook-to-setup-jenkins-slave\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"Ansible &#8211; Example playbook to setup Jenkins slave"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/e83488f033bd62395bd3eb801ddf8972","name":"Mohamed El Moussaoui","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d239ca3a713280c0c1b58648c249fd57?s=96&d=mm&r=g","caption":"Mohamed El Moussaoui"},"url":"https:\/\/trifork.nl\/blog\/author\/mohamedm\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/7656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/83"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=7656"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/7656\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=7656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=7656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=7656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}