first test disk service pipeline
This commit is contained in:
@ -116,25 +116,30 @@ all:
|
|||||||
IFS=',' read -ra IPS <<< "$IP_LIST"
|
IFS=',' read -ra IPS <<< "$IP_LIST"
|
||||||
for IP in "${IPS[@]}"; do
|
for IP in "${IPS[@]}"; do
|
||||||
ip_check=$(curl -s http://172.25.100.15:15010/ip_check?ip=${IP} | jq .in_subnets)
|
ip_check=$(curl -s http://172.25.100.15:15010/ip_check?ip=${IP} | jq .in_subnets)
|
||||||
echo $ip_check
|
|
||||||
echo $allsubnet_group
|
|
||||||
echo $SERVER_SUBNET_GROUP
|
|
||||||
# if this is a restricted subnet, then check the group
|
# if this is a restricted subnet, then check the group
|
||||||
if $ip_check; then
|
if $ip_check; then
|
||||||
|
if ! $be_quiet; then
|
||||||
echo "Subnet restricted, checking group membership"
|
echo "Subnet restricted, checking group membership"
|
||||||
|
fi
|
||||||
if [ "$allsubnet_group" == "$SERVER_SUBNET_GROUP" ]; then
|
if [ "$allsubnet_group" == "$SERVER_SUBNET_GROUP" ]; then
|
||||||
|
if ! $be_quiet; then
|
||||||
echo "IP Check Passed, adding endpoint ${IP} to inventory"
|
echo "IP Check Passed, adding endpoint ${IP} to inventory"
|
||||||
|
fi
|
||||||
inventory_content+=" ${IP}:
|
inventory_content+=" ${IP}:
|
||||||
ansible_host: ${IP}
|
ansible_host: ${IP}
|
||||||
|
|
||||||
"
|
"
|
||||||
else
|
else
|
||||||
|
if ! $be_quiet; then
|
||||||
echo "Warning: User ${JENKINS_USER} not member of ${SERVER_SUBNET_GROUP}!"
|
echo "Warning: User ${JENKINS_USER} not member of ${SERVER_SUBNET_GROUP}!"
|
||||||
echo "Auth Check Failed for endpoint ${IP}, not adding to inventory"
|
echo "Auth Check Failed for endpoint ${IP}, not adding to inventory"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
# if the subnet is not restricted, just add the endpoint to the inventory
|
# if the subnet is not restricted, just add the endpoint to the inventory
|
||||||
else
|
else
|
||||||
|
if ! $be_quiet; then
|
||||||
echo "Unrestricted subnet, adding endpoint ${IP} to inventory"
|
echo "Unrestricted subnet, adding endpoint ${IP} to inventory"
|
||||||
|
fi
|
||||||
inventory_content+=" ${IP}:
|
inventory_content+=" ${IP}:
|
||||||
ansible_host: ${IP}
|
ansible_host: ${IP}
|
||||||
"
|
"
|
||||||
|
|||||||
74
jenkins/Jenkinsfile.disk_service
Normal file
74
jenkins/Jenkinsfile.disk_service
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
|
||||||
|
// Define parameters
|
||||||
|
parameters {
|
||||||
|
string(name: 'host_ip', description: 'Target System Address')
|
||||||
|
// string(name: 'new_hostname', description: 'Update Hostname')
|
||||||
|
// reference for later
|
||||||
|
// choice(name: 'DEPLOY_ENV', choices: ['dev', 'staging', 'prod'], description: 'Environment to deploy to')
|
||||||
|
// booleanParam(name: 'rename_host', defaultValue: true, description: 'When checked hostname will be renamed')
|
||||||
|
// booleanParam(name: 'config_matt', defaultValue: true, description: 'config matt profile')
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
ANSIBLE_FORCE_COLOR = '1'
|
||||||
|
ansible_service_windows = credentials(' ansible-service-windows')
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
ansiColor('xterm')
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
|
||||||
|
stage('Generate Inventory File') {
|
||||||
|
steps {
|
||||||
|
|
||||||
|
// Generate the dynamic inventory file
|
||||||
|
// Usage: $0 -i IP_LIST -u JENKINS_USER -g JENKINS_GROUP -w WINDOWS_USER -p ANSIBLE_PASSWORD [-a SERVER_SUBNET_GROUP] [-s] [-v] [-e]"
|
||||||
|
sh """
|
||||||
|
|
||||||
|
jenkins_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep -v \$SERVER_SUBNET_GROUP | grep Jenkins | head -n 1)
|
||||||
|
jenkins_subnet_group=\$(echo ${env.BUILD_USER_GROUPS} | sed 's/,/\\n/g' | grep -e authenticated -e \$SERVER_SUBNET_GROUP | sort -rf | head -n 1)
|
||||||
|
jenkins_user=\$(echo ${env.BUILD_USER})
|
||||||
|
cd /var/jenkins_home/ansible-windows
|
||||||
|
chmod +x /var/jenkins_home/ansible-windows/inventory/inventory.sh
|
||||||
|
/var/jenkins_home/ansible-windows/inventory/inventory.sh -v -s -a \$jenkins_subnet_group -g \$jenkins_group -u \$jenkins_user -w ${env.ansible_service_windows_USR} -p ${env.ansible_service_windows_PSW} -i ${params.host_ip}
|
||||||
|
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Ansible Playbook') {
|
||||||
|
steps {
|
||||||
|
sh """
|
||||||
|
echo Generate Hash
|
||||||
|
echo ${params.host_ip}
|
||||||
|
hash=\$(echo -n ${params.host_ip} | md5sum | cut -c 1-8)
|
||||||
|
|
||||||
|
inventory_file="/var/jenkins_home/ansible-windows/.inv/inventory-\$hash.yml"
|
||||||
|
playbook_file="/var/jenkins_home/ansible-windows/playbooks/disk_service.yaml"
|
||||||
|
|
||||||
|
cd /var/jenkins_home/ansible-windows
|
||||||
|
|
||||||
|
ansible-playbook -i \$inventory_file \$playbook_file \
|
||||||
|
--ssh-common-args='-o StrictHostKeyChecking=no'
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
// Remove dynamic Inventory file
|
||||||
|
sh """
|
||||||
|
hash=\$(echo -n "${params.host_ip}" | md5sum | cut -c 1-8)
|
||||||
|
inventory_file="/var/jenkins_home/ansible-windows/.inv/inventory-\$hash.yml"
|
||||||
|
rm \$inventory_file
|
||||||
|
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
13
playbooks/disk_service.yaml
Normal file
13
playbooks/disk_service.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
- name: Set up disk inventory service
|
||||||
|
hosts: all
|
||||||
|
become: yes
|
||||||
|
become_method: runas
|
||||||
|
|
||||||
|
roles:
|
||||||
|
|
||||||
|
- show_user_vars
|
||||||
|
|
||||||
|
- storage_api
|
||||||
|
|
||||||
|
...
|
||||||
@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
# https://us.fanntik.top/product/fanttik-e1-max-precision-electric-screwdriver-5/
|
- name: Ansible Windows Test
|
||||||
- name: Ansible Test
|
|
||||||
hosts: all
|
hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
become_method: runas
|
become_method: runas
|
||||||
|
|||||||
13
roles/storage_api/defaults/main.yaml
Normal file
13
roles/storage_api/defaults/main.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
#python_venv: "C:\Python39\Scripts"
|
||||||
|
|
||||||
|
cosmos_root_folder: "C:\programdata\cosmos"
|
||||||
|
|
||||||
|
python_service_root: "{{ cosmos_root_folder }}\python"
|
||||||
|
|
||||||
|
python_venv: "{{python_service_root}}\disk_api"
|
||||||
|
|
||||||
|
nssm_folder: "{{ cosmos_root_folder }}\nssm"
|
||||||
|
|
||||||
|
...
|
||||||
2
roles/storage_api/files/requirements.txt
Normal file
2
roles/storage_api/files/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Flask
|
||||||
|
psutil
|
||||||
15
roles/storage_api/tasks/build_py_bin.yaml
Normal file
15
roles/storage_api/tasks/build_py_bin.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Create directory structure
|
||||||
|
ansible.windows.win_file:
|
||||||
|
path: "{{ python_service_root }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Copy disk_service.py
|
||||||
|
ansible.windows.win_copy:
|
||||||
|
src: disk_service.py
|
||||||
|
dest: "{{ python_service_root }}\disk_service.py"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
...
|
||||||
17
roles/storage_api/tasks/main.yaml
Normal file
17
roles/storage_api/tasks/main.yaml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
###############################################
|
||||||
|
# Disk API Windows Service
|
||||||
|
###############################################
|
||||||
|
|
||||||
|
- name: set up python venv
|
||||||
|
include_tasks: python_venv.yaml
|
||||||
|
|
||||||
|
- name: build python exe
|
||||||
|
include_tasks: build_py_bin.yaml
|
||||||
|
|
||||||
|
#- name: set up nssm service
|
||||||
|
# include_tasks: nssm.yaml
|
||||||
|
|
||||||
|
|
||||||
|
...
|
||||||
13
roles/storage_api/tasks/nssm.yaml
Normal file
13
roles/storage_api/tasks/nssm.yaml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Install nssm
|
||||||
|
win_chocolatey:
|
||||||
|
name: nssm
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Install the foo service
|
||||||
|
community.windows.win_nssm:
|
||||||
|
name: foo
|
||||||
|
application: C:\windows\foo.exe
|
||||||
|
|
||||||
|
...
|
||||||
31
roles/storage_api/tasks/python_venv.yaml
Normal file
31
roles/storage_api/tasks/python_venv.yaml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Ensure Python is installed
|
||||||
|
win_chocolatey:
|
||||||
|
name: python
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Create venv folder
|
||||||
|
ansible.windows.win_file:
|
||||||
|
path: "{{ python_venv }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Copy requirements.txt
|
||||||
|
ansible.windows.win_copy:
|
||||||
|
src: requirements.txt
|
||||||
|
dest: "{{ python_venv }}\requirements.txt"
|
||||||
|
|
||||||
|
- name: Create virtual environment
|
||||||
|
win_shell: "py -m venv {{ python_venv }}"
|
||||||
|
|
||||||
|
- name: Upgrade pip in the virtual environment
|
||||||
|
win_shell: "{{ python_venv }}\pip install --upgrade pip"
|
||||||
|
args:
|
||||||
|
chdir: "{{ python_venv }}"
|
||||||
|
|
||||||
|
- name: Install Python dependencies from requirements.txt
|
||||||
|
win_shell: "{{ python_venv }}\pip install -r {{ python_venv }}\requirements.txt"
|
||||||
|
args:
|
||||||
|
chdir: "{{ python_venv }}"
|
||||||
|
|
||||||
|
...
|
||||||
Reference in New Issue
Block a user