From c059b9fd84c2fca3cc9479eeda7e5d51af5c78d7 Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 20 Apr 2026 14:51:45 -0400 Subject: [PATCH] first commit --- Jenkinsfile | 82 +++++++++++++++++++++++++++++++++++++ ansible.cfg | 7 ++++ playbooks/docker.yml | 8 ++++ playbooks/nfs.yml | 12 ++++++ roles/docker/tasks/main.yml | 63 ++++++++++++++++++++++++++++ roles/nfs/tasks/main.yml | 65 +++++++++++++++++++++++++++++ 6 files changed, 237 insertions(+) create mode 100644 Jenkinsfile create mode 100644 ansible.cfg create mode 100644 playbooks/docker.yml create mode 100644 playbooks/nfs.yml create mode 100644 roles/docker/tasks/main.yml create mode 100644 roles/nfs/tasks/main.yml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..aef2b66 --- /dev/null +++ b/Jenkinsfile @@ -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." + } + } +} diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..119030c --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,7 @@ +[defaults] +roles_path = roles +host_key_checking = False + +[ssh_connection] +ssh_args = -o ControlMaster=auto -o ControlPersist=60s +pipelining = True diff --git a/playbooks/docker.yml b/playbooks/docker.yml new file mode 100644 index 0000000..060d664 --- /dev/null +++ b/playbooks/docker.yml @@ -0,0 +1,8 @@ +--- +- name: Install Docker and Docker Compose + hosts: all + become: true + gather_facts: true + + roles: + - docker diff --git a/playbooks/nfs.yml b/playbooks/nfs.yml new file mode 100644 index 0000000..cd19c35 --- /dev/null +++ b/playbooks/nfs.yml @@ -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 diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml new file mode 100644 index 0000000..1fb0841 --- /dev/null +++ b/roles/docker/tasks/main.yml @@ -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 diff --git a/roles/nfs/tasks/main.yml b/roles/nfs/tasks/main.yml new file mode 100644 index 0000000..1baa815 --- /dev/null +++ b/roles/nfs/tasks/main.yml @@ -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