-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstalldocker+jenkins.yaml
133 lines (108 loc) · 3.55 KB
/
installdocker+jenkins.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
- hosts: docker_jenkins
become: true
gather_facts: yes
tasks:
- name: Update the repositories
apt:
update_cache: yes
- name: Create /etc/apt/keyrings directory
command: install -m 0755 -d /etc/apt/keyrings
- name: Download and install Docker GPG key
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- name: Run command to set permissions
command: chmod a+r /etc/apt/keyrings/docker.gpg
- name: Run command to add Docker repository
shell: |
echo "deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
- name: Update the repositories
apt:
update_cache: yes
- name: Install the docker packages
apt:
name: ['docker-ce', 'docker-ce-cli', 'containerd.io', 'docker-buildx-plugin', 'docker-compose-plugin']
state: present
- name: Enable the docker service
systemd:
name: docker
enabled: true
- name: Start the docker service
service:
name: docker
state: started
- name: Download long term jenkins release
get_url:
url: https://pkg.jenkins.io/redhat-stable/jenkins.repo
dest: /etc/yum.repos.d/jenkins.repo
when: ansible_distribution == 'RedHat'
- name: Download long term jenkins release
lineinfile:
path: /etc/apt/sources.list.d/jenkins.list
line: "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/"
create: yes
when: ansible_pkg_mgr == 'apt'
- name: Install epel release package for extra packages
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
state: present
disable_gpg_check: true
when: ansible_distribution == 'RedHat'
- name: Execute curl command
shell: curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
when: ansible_pkg_mgr == 'apt'
- name: Import jenkins key from url
rpm_key:
key: https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
state: present
when: ansible_distribution == 'RedHat'
- name: Update package repository
apt:
update_cache: yes
when: ansible_pkg_mgr == 'apt'
- name: Update package repository
yum:
update_cache: yes
when: ansible_distribution == 'RedHat'
- name: Install java
yum:
name: java-11-openjdk-devel
state: present
when: ansible_distribution == 'RedHat'
- name: Install java
apt:
name: openjdk-11-jdk
state: present
when: ansible_pkg_mgr == 'apt'
- name: Install jenkins
yum:
name: jenkins
state: latest
skip_broken: yes
when: ansible_distribution == 'RedHat'
- name: Install jenkins
apt:
name: jenkins
state: latest
when: ansible_pkg_mgr == 'apt'
- name: Start jenkins
service:
name: jenkins
state: started
- name: Enable jenkins
systemd:
name: jenkins
enabled: true
- name: Sleep for 30 seconds and continue to play
wait_for:
delay: 30
port: 8080
- name: Initialize jenkins password
shell: cat /var/lib/jenkins/secrets/initialAdminPassword
changed_when: false
register: result
- name: Print jenkins password
debug:
var: result.stdout
- name: user add into docker group
command: usermod -aG docker jenkins
...