About | Contents | Technologies | Requirements | Starting | License | Author
Jenkins Server Provisioning with Ansible Role. Checkout the main.yml file for steps to use this role.
- 🎯 About
- ✨ Contents
- 🚀 Technologies
- ✅ Requirements
- 🏁 Starting
- 🚀 Usage
- 💄 Groovy Script
- 📝 License
- 👷 Author Information
The following tools were used in this project:
Before starting 🏁, you need to have Git and Terraform installed on your machine.
# 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
- 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"
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()
This project is under license from Apache 2.0. For more details, see the LICENSE file.
Made with ❤️ by devenes