first commit
This commit is contained in:
82
Jenkinsfile
vendored
Normal file
82
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
string(
|
||||||
|
name: 'TARGET_HOST',
|
||||||
|
defaultValue: '',
|
||||||
|
description: 'Hostname or IP address of the target machine (e.g. 192.168.0.50 or myserver.lan)'
|
||||||
|
)
|
||||||
|
booleanParam(
|
||||||
|
name: 'INSTALL_DOCKER',
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Install Docker and Docker Compose'
|
||||||
|
)
|
||||||
|
booleanParam(
|
||||||
|
name: 'INSTALL_NFS_FOLDER',
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Install NFS and mount the NFSFolder share (/var/NFSFolder)'
|
||||||
|
)
|
||||||
|
booleanParam(
|
||||||
|
name: 'INSTALL_NFS_VAULT',
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Install NFS and mount the Vault share (/var/vault)'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
ANSIBLE_CONFIG = "${WORKSPACE}/ansible.cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Validate') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
if (!params.TARGET_HOST?.trim()) {
|
||||||
|
error 'TARGET_HOST is required — enter the hostname or IP of the target machine.'
|
||||||
|
}
|
||||||
|
if (!params.INSTALL_DOCKER && !params.INSTALL_NFS_FOLDER && !params.INSTALL_NFS_VAULT) {
|
||||||
|
error 'Select at least one installation option.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Install Docker') {
|
||||||
|
when {
|
||||||
|
expression { return params.INSTALL_DOCKER }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh """
|
||||||
|
ansible-playbook \
|
||||||
|
-i "${params.TARGET_HOST}," \
|
||||||
|
playbooks/docker.yml
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Install NFS') {
|
||||||
|
when {
|
||||||
|
expression { return params.INSTALL_NFS_FOLDER || params.INSTALL_NFS_VAULT }
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh """
|
||||||
|
ansible-playbook \
|
||||||
|
-i "${params.TARGET_HOST}," \
|
||||||
|
-e "install_nfs_folder=${params.INSTALL_NFS_FOLDER}" \
|
||||||
|
-e "install_nfs_vault=${params.INSTALL_NFS_VAULT}" \
|
||||||
|
playbooks/nfs.yml
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
success {
|
||||||
|
echo "Provisioning complete on ${params.TARGET_HOST}."
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "Provisioning failed on ${params.TARGET_HOST}. Check the stage logs above."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
ansible.cfg
Normal file
7
ansible.cfg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[defaults]
|
||||||
|
roles_path = roles
|
||||||
|
host_key_checking = False
|
||||||
|
|
||||||
|
[ssh_connection]
|
||||||
|
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
|
||||||
|
pipelining = True
|
||||||
8
playbooks/docker.yml
Normal file
8
playbooks/docker.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Install Docker and Docker Compose
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- docker
|
||||||
12
playbooks/nfs.yml
Normal file
12
playbooks/nfs.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
- name: Install NFS and configure mounts
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
gather_facts: true
|
||||||
|
|
||||||
|
vars:
|
||||||
|
install_nfs_folder: false
|
||||||
|
install_nfs_vault: false
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- nfs
|
||||||
63
roles/docker/tasks/main.yml
Normal file
63
roles/docker/tasks/main.yml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
- name: Install required packages for Docker
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- apt-transport-https
|
||||||
|
- ca-certificates
|
||||||
|
- curl
|
||||||
|
- gnupg
|
||||||
|
- lsb-release
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Create keyrings directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/apt/keyrings
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Add Docker GPG key
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: https://download.docker.com/linux/ubuntu/gpg
|
||||||
|
dest: /etc/apt/keyrings/docker.asc
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
|
- name: Get system architecture
|
||||||
|
ansible.builtin.command: dpkg --print-architecture
|
||||||
|
register: dpkg_arch
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Get Ubuntu codename
|
||||||
|
ansible.builtin.command: lsb_release -cs
|
||||||
|
register: ubuntu_codename
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Add Docker repository
|
||||||
|
ansible.builtin.apt_repository:
|
||||||
|
repo: "deb [arch={{ dpkg_arch.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ubuntu_codename.stdout }} stable"
|
||||||
|
state: present
|
||||||
|
filename: docker
|
||||||
|
|
||||||
|
- name: Install Docker packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Ensure Docker service is started and enabled
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: docker
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
- name: Add jerick user to docker group
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: jerick
|
||||||
|
groups: docker
|
||||||
|
append: true
|
||||||
|
ignore_errors: true
|
||||||
65
roles/nfs/tasks/main.yml
Normal file
65
roles/nfs/tasks/main.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
- name: Install NFS client packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- nfs-common
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Create NFSFolder mount directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /var/NFSFolder
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
when: install_nfs_folder | default(false) | bool
|
||||||
|
|
||||||
|
- name: Add NFSFolder mount to fstab
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/fstab
|
||||||
|
line: "192.168.0.161:/mnt/share1/NFSFolder /var/NFSFolder nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0"
|
||||||
|
state: present
|
||||||
|
create: true
|
||||||
|
when: install_nfs_folder | default(false) | bool
|
||||||
|
|
||||||
|
- name: Reload systemd daemon
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
when: install_nfs_folder | default(false) | bool
|
||||||
|
|
||||||
|
- name: Mount NFSFolder share
|
||||||
|
ansible.posix.mount:
|
||||||
|
path: /var/NFSFolder
|
||||||
|
src: "192.168.0.161:/mnt/share1/NFSFolder"
|
||||||
|
fstype: nfs
|
||||||
|
opts: "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800"
|
||||||
|
state: mounted
|
||||||
|
when: install_nfs_folder | default(false) | bool
|
||||||
|
|
||||||
|
- name: Create vault mount directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /var/vault
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
when: install_nfs_vault | default(false) | bool
|
||||||
|
|
||||||
|
- name: Add vault mount to fstab
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/fstab
|
||||||
|
line: "vault.lan:/mnt/vault /var/vault nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0"
|
||||||
|
state: present
|
||||||
|
create: true
|
||||||
|
when: install_nfs_vault | default(false) | bool
|
||||||
|
|
||||||
|
- name: Reload systemd daemon
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
daemon_reload: true
|
||||||
|
when: install_nfs_vault | default(false) | bool
|
||||||
|
|
||||||
|
- name: Mount vault share
|
||||||
|
ansible.posix.mount:
|
||||||
|
path: /var/vault
|
||||||
|
src: "vault.lan:/mnt/vault"
|
||||||
|
fstype: nfs
|
||||||
|
opts: "auto,nofail,noatime,nolock,intr,tcp,actimeo=1800"
|
||||||
|
state: mounted
|
||||||
|
when: install_nfs_vault | default(false) | bool
|
||||||
Reference in New Issue
Block a user