Tuesday, August 29, 2023

Install Jenkins using Ansible

  Ansible Playbook with Jenkins Pipeline | by Prashant Bhatasana | AppGambit  | Medium

Ansible

Install Jenkins using Ansible Playbook. Create a Playbook called Jenkins.yml

cat jenkins.yml
- hosts: localhost
  become: yes
  become_method: sudo
  become_flags: -s
  become_user: root
  tasks:
   - name: Install Jenkins
     shell: |
      wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
      sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
      /etc/apt/sources.list.d/jenkins.list'
      sudo apt-get update
      yes | sudo apt-get install jenkins

ansible@ansible-VirtualBox:~/Desktop$ ansible-playbook jenkins.yml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [localhost] ******************************************************************************************************************************************************************************************

TASK [Gathering Facts] ************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Install Jenkins] ************************************************************************************************************************************************************************************
[WARNING]: Consider using the get_url or uri module rather than running 'wget'.  If you need to use command because get_url or uri is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [localhost] => changed=true
  cmd: |-
    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
    sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
    /etc/apt/sources.list.d/jenkins.list'
    sudo apt-get update
    yes | sudo apt-get install jenkins
  delta: '0:03:37.888632'
  end: '2021-04-25 16:17:45.946913'
  rc: 0
  start: '2021-04-25 16:14:08.058281'
  stderr: 'Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).'
  stderr_lines: <omitted>
  stdout: |-
    OK
    Hit:1 http://in.archive.ubuntu.com/ubuntu groovy InRelease
    Ign:2 https://pkg.jenkins.io/debian-stable binary/ InRelease
    Hit:3 https://pkg.jenkins.io/debian-stable binary/ Release
    Hit:5 http://security.ubuntu.com/ubuntu groovy-security InRelease
    Hit:6 http://in.archive.ubuntu.com/ubuntu groovy-updates InRelease
    Hit:7 http://in.archive.ubuntu.com/ubuntu groovy-backports InRelease
    Hit:8 https://download.docker.com/linux/ubuntu groovy InRelease
    Reading package lists...
    Reading package lists...
    Building dependency tree...
    Reading state information...
    The following additional packages will be installed:
      daemon net-tools
    The following NEW packages will be installed:
      daemon jenkins net-tools
    0 upgraded, 3 newly installed, 0 to remove and 251 not upgraded.
    Need to get 68.3 MB/68.6 MB of archives.
    After this operation, 72.1 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Get:1 https://pkg.jenkins.io/debian-stable binary/ jenkins 2.277.3 [68.3 MB]
    Fetched 15.5 MB in 3min 5s (83.8 kB/s)
    Selecting previously unselected package daemon.
    (Reading database ... (Reading database ... 5%(Reading database ... 10%(Reading database ... 15%(Reading database ... 20%(Reading database ... 25%(Reading database ... 30%(Reading database ... 35%(Reading database ... 40%(Reading database ... 45%(Reading database ... 50%(Reading database ... 55%(Reading database ... 60%(Reading database ... 65%(Reading database ... 70%(Reading database ... 75%(Reading database ... 80%(Reading database ... 85%(Reading database ... 90%(Reading database ... 95%(Reading database ... 100%(Reading database ... 271868 files and directories currently installed.)
    Preparing to unpack .../daemon_0.6.4-1build2_amd64.deb ...
    Unpacking daemon (0.6.4-1build2) ...
    Selecting previously unselected package net-tools.
    Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu2_amd64.deb ...
    Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu2) ...
    Selecting previously unselected package jenkins.
    Preparing to unpack .../jenkins_2.277.3_all.deb ...
    Unpacking jenkins (2.277.3) ...
    Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu2) ...
    Setting up daemon (0.6.4-1build2) ...
    Setting up jenkins (2.277.3) ...
    Processing triggers for man-db (2.9.3-2) ...
    Processing triggers for systemd (246.6-1ubuntu1) ...
  stdout_lines: <omitted>

PLAY RECAP ************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  


Once the step is complete, follow the below link to continue with Jenkins installation ->

http://localhost:8080

https://devopsapt.blogspot.com/2020/06/install-jenkins-on-linux.html

Jenkins is setup: