Configure Jenkins 2.0 with Ansible

I am using Ansible for provision our servers, I installed the Jenkins 2.0 but it is becomeing with a startup configuration when I open the web UI. How can I do it with Ansible or shell or jenkins-cli. CentOS 7, Ansible

  1. Installing Jenkins 2.0 from rpm.
  2. Install java with yum.
  3. Service start jenkins.
  4. Open, which is opening the Jenkins.
  5. In Web UI adding the initial admin password.
  6. In web UI select and install plugins.
  7. In web UI create a new admin user.

The 5,6,7 points are all the startup config of the new Jenkins. I haven’t idea how we can install it autmatically.

  • How to diff ansible vault changes?
  • The best way to apply a git patch via Ansible
  • Ansible SSH private key in source control?
  • Can't checkout to a new branch - ansible git
  • private repo is getting cloned via ansible playbook but private gem are not getting installed
  • How to push a playbook into Ansible tower
  • Edit 1:

    The 1,2,3 point is already done, just I didn’t share because it is not necessary, because I only need an advice how can I configure the Jenkins. But now I add it to my question.

    - name: Jenkins - install | Install java
      yum: name=java state=installed
    - name: Jenkins - install | Install Jenkins 2.0
      yum: pkg= state=installed
    - name: Jenkins - install | Start and enable Jenkins 2.0
      service: name=jenkins state=started enabled=yes

  • How to run Selenium tests using TestNG framework and Jenkins
  • Jenkins slave jobs failing on “Unexpected termination of channel”
  • git commits into html filr through jenkins
  • Consolidate Jenkins Email Notifications
  • Limiting log size of jenkins.log or hudson.log
  • How to use the 'Issue attribute path' in the parameter mapping of jenkins-trigger-plugin
  • 4 Solutions collect form web for “Configure Jenkins 2.0 with Ansible”

    You can create initialization script (in groovy) to add admin account.
    Script should be present in $JENKINS_HOME/init.groovy.d/*.groovy.
    Jenkins CI Wiki

    There is an example:

    import jenkins.model.*
    def instance = Jenkins.getInstance()
    println "--> Checking if security has been set already"
    if (!instance.isUseSecurity()) {
        println "--> creating local user 'admin'"
        def hudsonRealm = new HudsonPrivateSecurityRealm(false)
        hudsonRealm.createAccount('{{ jenkins_admin_username }}', '{{ jenkins_admin_password }}')
        def strategy = new FullControlOnceLoggedInAuthorizationStrategy()

    Link to GitHub reposiotry.

    I found a solution, this is turn off the setup wizard, after it I was able to change config files.

    - name: Jenkins - configure | Turn off Jenkins setup wizard
      lineinfile: dest=/etc/sysconfig/jenkins regexp='^JENKINS_JAVA_OPTIONS=' line='JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false"'
      notify: restart jenkins

    The above solution didn’t work for me but give me hint and this is the solution that worked for me on Ubuntu:

    - name: Configure JVM Arguments
        dest: /etc/default/jenkins
        regexp: '^JAVA_ARGS='
        line: 'JAVA_ARGS="-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false"'
        - Restart Jenkins

    On Ubuntu 16.04 with Jenkins installed using apt-get, this works:

    - name: "Turn off Jenkins setup wizard"
          dest: /etc/init.d/jenkins
          regexp: '^JAVA_ARGS='
          line: 'JAVA_ARGS="-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false"'
          insertbefore: '^DAEMON_ARGS='
      notify: restart jenkins
    - name: restart jenkins
      service: name=jenkins state=restarted

    You will still have to setup the security though!

    Git Baby is a git and github fan, let's start git clone.