-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-install.yml
More file actions
106 lines (90 loc) · 3.32 KB
/
Copy pathdocker-install.yml
File metadata and controls
106 lines (90 loc) · 3.32 KB
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
---
- name: Install Docker on Ubuntu
hosts: all
become: true
tasks:
- name: Update existing list of packages
ansible.builtin.apt:
update_cache: yes
- name: Install prerequisite packages
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
state: latest
- name: Add Docker GPG key
ansible.builtin.shell:
cmd: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- name: Add Docker repository
ansible.builtin.shell:
cmd: echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
- name: Update package list to recognize newly added Docker repository
ansible.builtin.apt:
update_cache: yes
- name: Install Docker
ansible.builtin.apt:
name: docker-ce
state: latest
- name: Ensure Docker service is running
ansible.builtin.systemd:
name: docker
state: started
enabled: yes
- name: Create directory for Docker Compose
ansible.builtin.file:
path: "{{ ansible_env.HOME }}/.docker/cli-plugins/"
state: directory
mode: '0755'
- name: Download Docker Compose
ansible.builtin.get_url:
url: "https://github.com/docker/compose/releases/download/v2.28.1/docker-compose-linux-x86_64"
dest: "{{ ansible_env.HOME }}/.docker/cli-plugins/docker-compose"
mode: '0755'
- name: Verify Docker Compose installation
ansible.builtin.command:
cmd: docker compose version
register: compose_version
changed_when: false
- debug:
msg: "{{ compose_version.stdout }}"
- name: Clone node.js app repository
git:
repo: https://github.com/pirzada03/devops_project.git
dest: /var/www/html/nodejs-app
- name: Create Jenkins data directory
ansible.builtin.file:
path: /home/ubuntu/jenkins_data/jenkins_home
state: directory
mode: '0755'
# Create docker-compose file for Jenkins
- name: Create Docker Compose file for Jenkins
ansible.builtin.copy:
dest: "/docker-compose.yml"
content: |
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:lts-jdk11
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- "/jenkins_data/jenkins_home:/var/jenkins_home"
mode: '0644'
# Run Docker Compose to start Jenkins
- name: Run Docker Compose to start Jenkins
ansible.builtin.shell:
cmd: docker-compose -f /docker-compose.yml up -d
chdir: /home/ubuntu
# Display Jenkins initial admin password
- name: Get Jenkins initial admin password
ansible.builtin.shell:
cmd: cat /jenkins_data/jenkins_home/secrets/initialAdminPassword
register: jenkins_password
changed_when: false
- name: Show Jenkins initial admin password
ansible.builtin.debug:
msg: "Jenkins initial admin password is: {{ jenkins_password.stdout }}"