Skip to content

infraform/jenkins-ansible-role-1

 
 

Repository files navigation

Jenkins Server Ansible Role

Jenkins Server Provisioning with Ansible Role

Github top language Github language count Repository size License

About   |   Contents   |   Technologies   |   Requirements   |   Starting   |   License   |   Author


🎯 About

Jenkins Server Provisioning with Ansible Role. Checkout the main.yml file for steps to use this role.

✨ Contents

🚀 Technologies

The following tools were used in this project:

✅ Requirements

Before starting 🏁, you need to have Git and Terraform installed on your machine.

🏁 Starting

# Clone the project
git clone https://github.com/devenes/jenkins-server-ansible-role.git

# Access the project folder
cd jenkins-server-ansible-role

# Edit your backend, variables and initialize terraform
terraform init

# Run the project with terraform
terraform apply -auto-approve

🚀 Usage

  • Check if Ansible is installed and connected to your hosts
ansible all --list-hosts
ansible all -m ping -o
  • Initialize Ansible role with using Ansible Galaxy
ansible-galaxy init roles/jenkins_build
  • Encrypt the Jenkins server login password with using Ansible Vault
ansible-vault encrypt secret.yml
# You can encrypt the password with:
# ansible-vault decrypt secret.yml
  • Run the project playbook with Ansible
ansible-playbook play.yml --ask-vault-pass
  • Write the Jenkins job to the xml file with using Ansible as management tool
ansible all -b -m shell -a "sudo java -jar /root/jenkins-cli.jar -s http://localhost:8080/ -auth @/root/jenkinsauth get-job "job_template" > /root/job.xml"
  • Get the Jenkins job
ansible all -b -m shell -a "cat /root/job.xml"
  • Get the Jenkins Password
ansible all -m shell -a "sudo cat /var/lib/jenkins/secrets/initialAdminPassword"

💄 Groovy Script

Write the Groovy script to create the login credentials for the Jenkins server with using Ansible as automation tool.

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

println "--> creating local user 'admin'"

def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount('admin', '{{ admin_pass }}')
instance.setSecurityRealm(hudsonRealm)

def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
strategy.setAllowAnonymousRead(false)
instance.setAuthorizationStrategy(strategy)
instance.save()

📝 License

This project is under license from Apache 2.0. For more details, see the LICENSE file.

👷 Author Information

Made with ❤️ by devenes

 

Back to top

About

Provision Jenkins Server and Configure with Terraform and Ansible Role.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 88.5%
  • Groovy 11.5%