Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        


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


## :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

 

Back to top