ansible jenkins centos

vi jenkins.yml

---
- name: Install Jenkins
  hosts: all
  gather_facts: false
  become: yes
  tasks:
    - name: Install yum
      yum:
        name:
          - wget
          - java-1.8.0-openjdk

    - name: Install yum
      yum:
        name:
          - wget
          - java-1.8.0-openjdk

    - name: Download jenkins.repo
      get_url:
        url: http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
        dest: /etc/yum.repos.d/jenkins.repo

    - name: Import Jenkins Key
      rpm_key:
        state: present
        key: https://jenkins-ci.org/redhat/jenkins-ci.org.key

    - name: Install Jenkins
      yum:
        name: jenkins
        state: present

    - name: Start & Enable Jenkins
      systemd:
        name: jenkins
        state: started
        enabled: true

    - name: Sleep for 30 seconds and continue with play
      wait_for: timeout=30

    - name: Get init password Jenkins
      shell: cat /var/lib/jenkins/secrets/initialAdminPassword
      changed_when: false
      register: result

    - name: Print init password Jenkins
      debug:
        var: result.stdout
[root@localhost ~]# ansible-playbook jenkins.yml 

PLAY [Install Jenkins] ****************************************************************


TASK [Install yum] ********************************************************************
ok: [192.168.45.136]

TASK [Download jenkins.repo] **********************************************************
changed: [192.168.45.136]

TASK [Import Jenkins Key] *************************************************************
changed: [192.168.45.136]

TASK [Install Jenkins] ****************************************************************
changed: [192.168.45.136]

TASK [Start & Enable Jenkins] *********************************************************
changed: [192.168.45.136]

TASK [Sleep for 30 seconds and continue with play] ************************************
ok: [192.168.45.136]

TASK [Get init password Jenkins] ****************************************************
ok: [192.168.45.136] => {
    "result.stdout": "ad13a0ea7b024b1ba7a4cd4cfc4cfdd9"
}

PLAY RECAP ****************************************************************************
192.168.45.136             : ok=9    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@localhost ~]# service jenkins status
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: active (running) since Fri 2019-09-06 10:31:13 IST; 4min 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 17604 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
    Tasks: 36
   CGroup: /system.slice/jenkins.service
           └─17627 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.a...

Sep 06 10:31:08 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automation ....
Sep 06 10:31:10 localhost.localdomain runuser[17610]: pam_unix(runuser:session): se...)
Sep 06 10:31:13 localhost.localdomain jenkins[17604]: Starting Jenkins [  OK  ]
Sep 06 10:31:13 localhost.localdomain systemd[1]: Started LSB: Jenkins Automation S....
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# ps -ef | grep jenkins
jenkins   17627      1 21 10:31 ?        00:01:04 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
root      18981  11462  0 10:36 pts/0    00:00:00 grep --color=auto jenkins

Comments