Skip to content

Commit c2a1a3c

Browse files
committed
feat: Jenkins Airgap Rancher and Airgap Harvester Pipeline Support
* brings in Jenkins pipeline * adjusts Debian based provisioning * adds additional credential * additional settings.yml.sample configuration * additional pipeline dependent plugin introduced * fixes existing provisioning issues due to the nature of hashicorp products Resolves: feat/air-gap-harvester-air-gap-rancher-cicd-pipelining-feat
1 parent 5082bc9 commit c2a1a3c

File tree

64 files changed

+2126
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2126
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Introduction
2+
3+
This is the Ansible to stand up a Jenkins Node that will use harvester-installer to create the artifacts for Harvester, for a pipeline in Jenkins that is capable of running AirGap Harvester & AirGap Rancher provisioning over Vagrant that leverages ipxe-examples (airgap version).
4+
5+
# Setup New Jenkins
6+
7+
To setup [Jenkins] on a target host.
8+
9+
1. Make sure [Ansible] is installed. You can install the latest version
10+
of [Ansible] using [Python PIP].
11+
2. Copy `settings.yml.sample` to `settings.yml`.
12+
3. Edit `settings.yml` by providing the required configurations. The
13+
configurations are self-documented.
14+
4. Edit `inventory.harvester-ci` to make sure the host IP and Ansible user are
15+
correct. **NOTE:** the Ansible user must have SSH access to the CI host and
16+
have sudo permissions.
17+
5. Run the `install_jenkins.ym` playbook. For example:
18+
19+
```console
20+
ansible-playbook -i inventor.harvester-ci --private-key <ansible user private key> install_jenkins.yml
21+
```
22+
23+
# Add a Jenkins Slave
24+
25+
To add a Jenkins Slave.
26+
27+
1. Make sure [Ansible] is installed. You can install the latest version
28+
of [Ansible] using [Python PIP].
29+
2. Copy `settings.yml.sample` to `settings.yml`.
30+
3. Edit `settings.yml` by providing the required configurations. The
31+
configurations are self-documented.
32+
4. Edit `inventory.harvester-ci` to make sure the host IP and Ansible user are
33+
correct. **NOTE:** the Ansible user must have SSH access to the CI host and
34+
have sudo permissions.
35+
5. Install the required packages on the Jenkins Slave host by running the
36+
`install_jenkins_slave.yml` playbook. For example:
37+
38+
```console
39+
ansible-playbook -i inventory.harvester-ci --private-key <ansible user private key> install_jenkins_slave.yml
40+
```
41+
42+
6. Manually add the new node from Jenkins Master.
43+
44+
[Ansible]: https://www.ansible.com/
45+
[Jenkins]: https://www.jenkins.io/
46+
[Python PIP]: https://pip.pypa.io/en/stable/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
- name: Install Jenkins on localhost
3+
hosts: harvester-ci
4+
become: yes
5+
vars:
6+
GITHUB_PROJECT: harvester/harvester-installer
7+
8+
tasks:
9+
- name: Include settings
10+
include_vars:
11+
file: settings.yml
12+
13+
- name: Check for supported OS version
14+
fail:
15+
msg: "OS must be openSUSE or Ubuntu"
16+
when: (ansible_distribution|lower != 'opensuse leap' and
17+
ansible_distribution|lower != 'ubuntu')
18+
19+
- name: Setup PKI
20+
include_role:
21+
name: pki
22+
when: JENKINS_PROXY_ENABLE_SSL
23+
24+
- name: Setup Nginx proxy
25+
include_role:
26+
name: nginx
27+
when: JENKINS_USE_PROXY
28+
29+
- name: Install Jenkins
30+
include_role:
31+
name: jenkins
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
- name: Install Jenkins Slave
3+
hosts: harvester-ci-slave
4+
become: yes
5+
6+
tasks:
7+
- name: Include settings
8+
include_vars:
9+
file: settings.yml
10+
11+
- name: Check for supported OS version
12+
fail:
13+
msg: "OS must be openSUSE or Ubuntu"
14+
when: (ansible_distribution|lower != 'opensuse leap' and
15+
ansible_distribution|lower != 'ubuntu')
16+
17+
- name: Install Jenkins Slave
18+
include_role:
19+
name: jenkins_slave
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[harvester-ci]
2+
master ansible_host= ansible_user=root
3+
4+
[harvester-ci-slave]
5+
slave ansible_host= ansible_user=root
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
JENKINS_ADMIN_USERNAME: admin
3+
JENKINS_ADMIN_PASSWORD: jenkins
4+
JENKINS_ADMIN_EMAIL: gyee@suse.com
5+
JENKINS_DEV_USERNAME: harvester
6+
JENKINS_DEV_PASSWORD: harvester
7+
JENKINS_PUBLIC_ENDPOINT: http://localhost:8080
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: jenkins | install_docker | Install Docker
3+
include_tasks: install_docker_on_{{ ansible_os_family }}.yml
4+
5+
- name: jenkins | install_docker | Add jenkins user to docker group
6+
user:
7+
name: jenkins
8+
groups: docker
9+
append: yes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: jenkins | install_docker_on_Debian |
3+
Install prerequisite packages for Docker
4+
apt:
5+
name: [apt-transport-https, ca-certificates, curl, software-properties-common]
6+
state: latest
7+
8+
- name: jenkins | install_docker_on_Debian | Add Docker apt repo key
9+
apt_key:
10+
url: https://download.docker.com/linux/ubuntu/gpg
11+
state: present
12+
13+
- name: jenkins | install_docker_on_Debian | Add Docker apt repo
14+
apt_repository:
15+
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
16+
state: present
17+
update_cache: true
18+
19+
- name: jenkins | install_docker_on_Debian | Install docker-ce package
20+
apt:
21+
name: docker-ce
22+
state: latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: jenkins | install_docker_on_Suse | Install Docker packages
3+
community.general.zypper:
4+
name: [docker, python3-docker-compose]
5+
state: latest
6+
7+
- name: jenkins | install_docker_on_Suse | Enable docker service
8+
service:
9+
name: docker
10+
enabled: yes
11+
state: started
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
- name: jenkins | install_jenkins | Set Jenkins bootstrap credential
3+
set_fact:
4+
JENKINS_BOOTSTRAP_USERNAME: jenkins_bootstrap_user
5+
JENKINS_BOOTSTRAP_PASSWORD: "{{ lookup('password', '/dev/null chars=ascii_letters,digits length=30') }}"
6+
7+
- name: jenkins | install_jenkins | Install Jenkins
8+
include_tasks: install_jenkins_on_{{ ansible_os_family }}.yml
9+
10+
- name: jenkins | install_jenkins | Wait for Jenkins to be ready
11+
uri:
12+
url: "http://localhost:8080/cli/"
13+
status_code: 200
14+
register: get_jenkins_cli_result
15+
until: get_jenkins_cli_result.status == 200
16+
retries: 10
17+
delay: 20
18+
19+
- name: jenkins | install_jenkins | Install Jenkins CLI
20+
get_url:
21+
url: "http://localhost:8080/jnlpJars/jenkins-cli.jar"
22+
dest: "/opt/jenkins-cli.jar"
23+
register: jarfile_get
24+
until: "'OK' in jarfile_get.msg or '304' in jarfile_get.msg or 'file already exists' in jarfile_get.msg"
25+
retries: 5
26+
delay: 10
27+
28+
- name: jenkins | install_jenkins | Create jenkins CLI to install plugins
29+
template:
30+
src: jenkins.j2
31+
dest: /usr/bin/jenkins
32+
mode: 0755
33+
force: yes
34+
vars:
35+
JENKINS_AUTH_USERNAME: "{{ JENKINS_BOOTSTRAP_USERNAME }}"
36+
JENKINS_AUTH_PASSWORD: "{{ JENKINS_BOOTSTRAP_PASSWORD }}"
37+
38+
- name: jenkins | install_jenkins | Install Jenkins plugins
39+
shell: >
40+
/usr/bin/jenkins install-plugin {{ item }}
41+
with_items:
42+
- ansible
43+
- authorize-project
44+
- build-timeout
45+
- blueocean
46+
- bootstrap5-api
47+
- configuration-as-code
48+
- credentials-binding
49+
- docker-workflow
50+
- email-ext
51+
- ghprb
52+
- git
53+
- github-branch-source
54+
- github-oauth
55+
- htmlpublisher
56+
- job-dsl
57+
- ldap
58+
- mailer
59+
- matrix-auth
60+
- pam-auth
61+
- pipeline-github-lib
62+
- pipeline-stage-view
63+
- pipeline-utility-steps
64+
- ssh-slaves
65+
- timestamper
66+
- workflow-aggregator
67+
- workflow-cps
68+
- workflow-job
69+
- ws-cleanup
70+
71+
- name: jenkins | install_jenkins | Remove Jenkins security bootstrap scripts
72+
file:
73+
path: /var/lib/jenkins/init.groovy.d/basic-security.groovy
74+
state: absent
75+
76+
- name: jenkins | install_jenkins | Create Jenkins ansible_playbooks directory
77+
file:
78+
path: /var/lib/jenkins/ansible_playbooks
79+
state: directory
80+
owner: jenkins
81+
group: jenkins
82+
mode: 0755
83+
when: false
84+
85+
- name: jenkins | install_jenkins | Create Jenkins config as code directory
86+
file:
87+
path: /var/lib/jenkins/casc_configs
88+
state: directory
89+
owner: jenkins
90+
group: jenkins
91+
mode: 0755
92+
93+
# supports airgap rancher airgap harvester pipeline
94+
- name: jenkins | install_jenkins | Build Jenkins .ssh directory
95+
ansible.builtin.file:
96+
path: /var/lib/jenkins/.ssh
97+
state: directory
98+
owner: jenkins
99+
group: jenkins
100+
101+
- name: jenkins | install_jenkins | Build known_hosts file
102+
ansible.builtin.file:
103+
path: /var/lib/jenkins/.ssh/known_hosts
104+
state: present
105+
106+
- name: jenkins | install_jenkins | Create Jenkins config as code file
107+
template:
108+
src: config_jenkins_as_code.yaml.j2
109+
dest: /var/lib/jenkins/casc_configs/config_jenkins_as_code.yaml
110+
owner: jenkins
111+
group: jenkins
112+
mode: 0644
113+
114+
- name: jenkins | install_jenkins | Copy pipeline jobs
115+
template:
116+
src: "{{ item }}.j2"
117+
dest: "/var/lib/jenkins/casc_configs/{{ item }}"
118+
owner: jenkins
119+
group: jenkins
120+
mode: 0755
121+
with_items:
122+
- airgap_rancher_airgap_harvester_pipelinejob.groovy
123+
124+
- name: jenkins | install_jenkins | Restart jenkins
125+
service:
126+
name: jenkins
127+
state: restarted
128+
129+
- name: jenkins | install_jenkins | Create jenkins CLI
130+
template:
131+
src: jenkins.j2
132+
dest: /usr/bin/jenkins
133+
mode: 0755
134+
force: yes
135+
vars:
136+
JENKINS_AUTH_USERNAME: "{{ JENKINS_ADMIN_USERNAME }}"
137+
JENKINS_AUTH_PASSWORD: "{{ JENKINS_ADMIN_PASSWORD }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
- name: jenkins | install_jenkins_on_Debian |
3+
Install prerequisite packages for Jenkins
4+
apt:
5+
name: [ca-certificates, openjdk-11-jdk, curl, apt-transport-https, gnupg,
6+
python3, python3-pip, figlet, sshpass]
7+
state: latest
8+
update_cache: yes
9+
10+
- name: jenkins | install_jenkins_on_Debian | Install Ansible
11+
pip:
12+
name: [pip, ansible]
13+
state: latest
14+
15+
- name: jenkins | install_jenkins_on_Debian | Add Jenkins apt repo key
16+
apt_key:
17+
url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
18+
state: present
19+
20+
- name: jenkins | install_jenkins_on_Debian | Add Jenkins apt repo
21+
apt_repository:
22+
repo: 'deb http://pkg.jenkins.io/debian-stable binary/'
23+
state: present
24+
update_cache: true
25+
26+
- name: jenkins | install_jenkins_on_Debian | Install Jenkins package
27+
apt:
28+
name: jenkins
29+
state: latest
30+
31+
- name: jenkins | install_jenkins_on_Debian | Stop jenkins service
32+
service:
33+
name: jenkins
34+
state: stopped
35+
36+
# NOTE(gyee): running this tasks repeatedly will add the same Java args
37+
# multiple time. But that should be fine so as long as the values are
38+
# consistent. However, if we are using this task to reconfigure any of the
39+
# args with a different value then the result may not be correct.
40+
# If we ever need to reconfigure Jenkins, it may be best to just do re-install.
41+
- name: jenkins | install_jenkins_on_Debian | Add Java options
42+
lineinfile:
43+
path: /etc/default/jenkins
44+
regexp: '^(JAVA_ARGS=\")(.*)$'
45+
line: '\1-Djenkins.install.runSetupWizard=false -Dcasc.jenkins.config=/var/lib/jenkins/casc_configs \2'
46+
state: present
47+
backrefs: yes
48+
mode: 0644
49+
50+
- name: jenkins | install_jenkins_on_Debian | Bind to localhost
51+
lineinfile:
52+
path: /etc/default/jenkins
53+
regexp: '^(JENKINS_ARGS=\")(.*)$'
54+
line: '\1--httpListenAddress=127.0.0.1 \2'
55+
state: present
56+
backrefs: yes
57+
mode: 0644
58+
when: JENKINS_USE_PROXY
59+
60+
- name: jenkins | install_jenkins_on_Debian |
61+
Create init.groovy.d to bootstrap Jenkins
62+
file:
63+
path: /var/lib/jenkins/init.groovy.d
64+
state: directory
65+
owner: jenkins
66+
group: jenkins
67+
mode: 0775
68+
69+
- name: jenkins | install_jenkins_on_Debian |
70+
Configure Jenkins bootstrap credential
71+
template:
72+
src: basic-security.groovy.j2
73+
dest: /var/lib/jenkins/init.groovy.d/basic-security.groovy
74+
owner: jenkins
75+
group: jenkins
76+
mode: 0755
77+
78+
- name: jenkins | install_jenkins_on_Debian | Restart Jenkins
79+
systemd:
80+
name: jenkins
81+
state: restarted
82+
83+
- name: jenkins | install_jenkins_on_Debian | Enable Jenkins port 8080
84+
shell: ufw allow 8080
85+

0 commit comments

Comments
 (0)