Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devenes/jenkins-server-ansible-role
Jenkins Server Provisioning and Configuration with Terraform and Ansible Role
https://github.com/devenes/jenkins-server-ansible-role
ansible groovy jenkins terraform
Last synced: 20 days ago
JSON representation
Jenkins Server Provisioning and Configuration with Terraform and Ansible Role
- Host: GitHub
- URL: https://github.com/devenes/jenkins-server-ansible-role
- Owner: devenes
- License: apache-2.0
- Created: 2022-06-15T16:33:41.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-17T00:17:58.000Z (over 2 years ago)
- Last Synced: 2024-11-09T07:35:11.632Z (3 months ago)
- Topics: ansible, groovy, jenkins, terraform
- Language: HCL
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Jenkins Server Provisioning with Ansible Role
About |
Contents |
Technologies |
Requirements |
Starting |
License |
Author
## :dart: About
Jenkins Server Provisioning with Ansible Role. Checkout the [main.yml](./roles/jenkins_build/tasks/main.yml) file for steps to use this role.
## :sparkles: Contents
- [:dart: About](#dart-about)
- [:sparkles: Contents](#sparkles-contents)
- [:rocket: Technologies](#rocket-technologies)
- [:white_check_mark: Requirements](#white_check_mark-requirements)
- [:checkered_flag: Starting](#checkered_flag-starting)
- [🚀 Usage](#-usage)
- [💄 Groovy Script](#-groovy-script)
- [:memo: License](#memo-license)
- [👷 Author Information](#-author-information)## :rocket: Technologies
The following tools were used in this project:
- [Terraform](https://www.terraform.io/)
- [Ansible](https://www.ansible.com/)## :white_check_mark: Requirements
Before starting :checkered_flag:, you need to have [Git](https://git-scm.com) and [Terraform](https://www.terraform.io/) installed on your machine.
## :checkered_flag: Starting
```bash
# 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
```bash
ansible all --list-hosts
ansible all -m ping -o
```- Initialize Ansible role with using Ansible Galaxy
```bash
ansible-galaxy init roles/jenkins_build
```- Encrypt the Jenkins server login password with using Ansible Vault
```bash
ansible-vault encrypt secret.yml
# You can encrypt the password with:
# ansible-vault decrypt secret.yml
```- Run the project playbook with Ansible
```bash
ansible-playbook play.yml --ask-vault-pass
```- Write the Jenkins job to the xml file with using Ansible as management tool
```bash
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
```bash
ansible all -b -m shell -a "cat /root/job.xml"
```- Get the Jenkins Password
```bash
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.
```groovy
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()
```## :memo: License
This project is under license from Apache 2.0. For more details, see the [LICENSE](LICENSE) file.
## 👷 Author Information
Made with :heart: by devenes