Ansible helper runbook to install Jenkins from ansible-role-jenkins
-
Install the collections and roles from requirements.yaml:
ansible-galaxy install -r requirements.yaml
-
Open the main.yaml file and adjust the parameters values as needed.
Note: you can set the
jenkins_admin_username
andjenkins_admin_password
variable values by using an Ansible vault file, see section Updating existing installation for a quick way to do -
Run the playbook on the target node:
time ansible-playbook main.yaml -i <node>, -b -K ## if run locally time ansible-playbook main.yaml -i "$(hostname -i)", -b -K --connection=local
For a clean installation on the target node we may need to remove some files to avoid package conflicts (only do this if you are definitely not using them), the commands below explain how to do it on RHEL distribution systems but adjust it for Ubuntu:
sudo dnf remove java-11-openjdk java jenkins java-1.8.0-openjdk-headless -y ; sudo dnf clean all ; sudo dnf clean packages ; sudo rm -rf /var/lib/jenkins /opt/jenkins-cli.jar
In case the default version of java needs to be replaced you can run:
update-alternatives --config java
You can update an existing installation by providing the jenkins_admin_username
and jenkins_admin_password
variables into a vault file:
-
Create a new Ansible vault:
ansible-vault create <path to>/jenkins_credentials.yaml
-
Enter a new password and confirm it.
-
Add the
jenkins_admin_username
andjenkins_admin_password
parameters with their corresponding values, example:jenkins_admin_username: "<username>" jenkins_admin_password: "<admin user password"
-
Save and quit.
-
Now we can run the playbook:
time ansible-playbook main.yaml -e @<path to>/jenkins_credentials.yaml --ask-vault-pass -i <node>, -b -K ## If run locally: time ansible-playbook main.yaml -e @<path to>/jenkins_credentials.yaml --ask-vault-pass -i "$(hostname -i)", -b -K --connection=local
-
If a specific version of Jenkins is needed then pass the following environmental variables to the command:
-e "jenkins_package_state=present jenkins_version=<version>"