- Security Automation with Ansible 2
- Madhu Akula Akash Mahajan
- 477字
- 2021-07-02 21:59:53
Setting up Jenkins
Let's use an Ansible playbook to install Jenkins and get started with it.
The following code snippet is a snippet of an Ansible playbook we wrote for setting up Jenkins in the Ubuntu 16.04 OS.
Once the setup has been done, playbook returns the default administrator password required to log in to the application for the first time:
- name: installing jenkins in ubuntu 16.04
hosts: "192.168.1.7"
remote_user: ubuntu
gather_facts: False
become: True
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
- name: install curl and git
apt: name={{ item }} state=present update_cache=yes
with_items:
- curl
- git
- name: adding jenkins gpg key apt_key: url: https://pkg.jenkins.io/debian/jenkins-ci.org.key state: present - name: jeknins repository to system apt_repository: repo: http://pkg.jenkins.io/debian-stable binary/ state: present - name: installing jenkins apt: name: jenkins state: present update_cache: yes
- name: adding jenkins to startup service: name: jenkins state: started enabled: yes - name: printing jenkins default administration password command: cat /var/lib/jenkins/secrets/initialAdminPassword register: jenkins_default_admin_password - debug: msg: "{{ jenkins_default_admin_password.stdout }}"
To set up Jenkins, run the following command. Where 192.168.1.7 is the server IP address where Jenkins will be installed:
ansible-playbook -i '192.168.1.7,' site.yml --ask-sudo-pass
Now we can configure Jenkins to install plugins, run scheduled jobs, and do many other things. First, we have to navigate to the Jenkins dashboard by browsing to http://192.168.1.7:8080 and providing the auto-generated password. If the playbook runs without any errors, it will display the password at the end of the play:

Create the new user by filling in the details and confirming to log in to the Jenkins console:

Now we can install custom plugins in Jenkins, navigate to the Manage Jenkins tab, select Manage Plugins, then navigate to the Available tab. In the Filter: enter the plugin name as Ansible. Then select the checkbox and click Install without restart:

Now we are ready to work with the Ansible plugin for Jenkins. Create a new project in the main dashboard, give it a name, and select Freestyle project to proceed:

Now we can configure the build options, this is where Jenkins will give us more flexibility to define our own triggers, build instructions, and post build scripts:

The preceding screenshot is an example of a build invoking an Ansible ad-hoc command. This can be modified to ansible-playbook or any other scripts based on certain events.
The Jenkins Ansible plugin also provides useful features such as configuring advanced commands and passing credentials, keys from Jenkins itself.
Once the build triggers based on an event, this can be sent to some artifact storage, it can also be available in the Jenkins build console output:

This is a really very powerful way to perform dynamic operations such as triggering automated server and stacks setup based on a code push to the repository, as well as scheduled scans and automated reporting.
- 智能傳感器技術(shù)與應(yīng)用
- 3D Printing with RepRap Cookbook
- PIC單片機(jī)C語(yǔ)言非常入門(mén)與視頻演練
- ROS機(jī)器人編程與SLAM算法解析指南
- Mastering Elastic Stack
- RPA:流程自動(dòng)化引領(lǐng)數(shù)字勞動(dòng)力革命
- AI 3.0
- Kubernetes for Developers
- Visual FoxPro程序設(shè)計(jì)
- 網(wǎng)絡(luò)管理工具實(shí)用詳解
- 在實(shí)戰(zhàn)中成長(zhǎng):Windows Forms開(kāi)發(fā)之路
- Mastering pfSense
- INSTANT VMware vCloud Starter
- Building Google Cloud Platform Solutions
- 電氣控制及Micro800 PLC程序設(shè)計(jì)