-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision.yml
96 lines (86 loc) · 2.72 KB
/
provision.yml
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
---
- name: Configurazione di Rocky Linux 9
hosts: all
become: true
tasks:
# Aggiorna tutti i pacchetti
- name: Aggiorna tutti i pacchetti
yum:
name: "*"
state: latest
# Installa pacchetti necessari
- name: Installa pacchetti necessari
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
- python3-pip
state: present
# Installa il modulo Python 'requests'
- name: Installa il modulo Python 'requests'
pip:
name: requests
executable: pip3
# Aggiungi il repository Docker CE
- name: Aggiungi il repository Docker CE
command: >
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Installa Docker CE
- name: Installa Docker CE
yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: present
# Abilita e avvia il servizio Docker
- name: Abilita e avvia il servizio Docker
systemd:
name: docker
enabled: true
state: started
# Creazione del volume Docker per Jenkins
- name: Crea il volume Docker per Jenkins
docker_volume:
name: jenkins_home
# Creazione della rete Docker per Jenkins
- name: Creazione di una rete Docker personalizzata
docker_network:
name: jenkins_network
driver: bridge
ipam_config:
- subnet: "172.20.0.0/16"
# Configurazione del container Jenkins Master
- name: Esegui il container Jenkins Master
docker_container:
name: jenkins_master
image: jenkins/jenkins:lts
state: started
restart_policy: always
user: root
networks:
- name: jenkins_network
ipv4_address: 172.20.0.2 # IP statico per il Master
ports:
- "8080:8080"
- "50000:50000"
# Configurazione del container Jenkins Slave (con accesso Docker)
- name: Esegui il container Jenkins Slave
docker_container:
name: jenkins_slave
image: jenkins/inbound-agent
state: started
restart_policy: always
user: root
networks:
- name: jenkins_network
ipv4_address: 172.20.0.3 # IP statico per lo Slave
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Monta il socket Docker per l'accesso al Docker Host
- jenkins_home:/var/jenkins_home # Volume per persistenza dati
env:
JENKINS_URL: http://172.20.0.2:8080
JENKINS_AGENT_NAME: "slave"
JENKINS_AGENT_WORKDIR: "/home/jenkins"
JENKINS_SECRET: "jenkins_secret" # Sostituisci con la chiave segreta del Master