disk service jenkinsfile less verbose
This commit is contained in:
@ -7,7 +7,7 @@ usage() {
|
||||
echo "Windows Ansible Dynamic Inventory File Generation Script"
|
||||
echo "Usage: $0 -i IP_LIST -u JENKINS_USER -g JENKINS_GROUP -w WINDOWS_USER -p ANSIBLE_PASSWORD [-a SERVER_SUBNET_GROUP] [-s] [-v] [-e]"
|
||||
echo "Options:"
|
||||
echo " -i IP_LIST Comma-separated list of IPs"
|
||||
echo " -i IP_LIST Comma-separated list of IPs. Will not fail if blank, but why 0_o"
|
||||
echo " -u JENKINS_USER Jenkins user"
|
||||
echo " -g JENKINS_GROUP Jenkins primary group"
|
||||
echo " -a SERVER_SUBNET_GROUP Jenkins group for SSH access, need to pass something when called"
|
||||
@ -62,7 +62,7 @@ while getopts ":i:u:w:p:g:a:svq" opt; do
|
||||
done
|
||||
shift $((OPTIND -1))
|
||||
# Check if all required options are provided
|
||||
if [ -z "$IP_LIST" ] || [ -z "$JENKINS_USER" ] || [ -z "$JENKINS_GROUP" ] || [ -z "$WINDOWS_USER" ] || [ -z "$ANSIBLE_PASSWORD" ]; then
|
||||
if [ -z "$JENKINS_USER" ] || [ -z "$JENKINS_GROUP" ] || [ -z "$WINDOWS_USER" ] || [ -z "$ANSIBLE_PASSWORD" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ pipeline {
|
||||
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}
|
||||
/var/jenkins_home/ansible-windows/inventory/inventory.sh -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}
|
||||
|
||||
"""
|
||||
}
|
||||
|
||||
@ -2,12 +2,20 @@
|
||||
|
||||
#python_venv: "C:\Python39\Scripts"
|
||||
|
||||
cosmos_root_folder: "C:\programdata\cosmos"
|
||||
cosmos_root_folder: "C:\\programdata\\cosmos"
|
||||
|
||||
python_service_root: "{{ cosmos_root_folder }}\python"
|
||||
python_service_root: "{{ cosmos_root_folder }}\\python"
|
||||
|
||||
python_venv: "{{python_service_root}}\disk_api"
|
||||
storage_api_root: "{{ python_service_root }}\\disk_api"
|
||||
|
||||
nssm_folder: "{{ cosmos_root_folder }}\nssm"
|
||||
python_venv: "{{storage_api_root}}\\venv"
|
||||
|
||||
python_venv_bin: "{{ python_venv }}\\Scripts\\python.exe"
|
||||
|
||||
python_venv_pip_bin: "{{ python_venv }}\\Scripts\\pip.exe"
|
||||
|
||||
nssm_folder: "{{ cosmos_root_folder }}\\nssm"
|
||||
|
||||
disk_service_name: "disk_api"
|
||||
|
||||
...
|
||||
@ -1,15 +0,0 @@
|
||||
---
|
||||
|
||||
- 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"
|
||||
|
||||
|
||||
|
||||
...
|
||||
@ -8,10 +8,11 @@
|
||||
include_tasks: python_venv.yaml
|
||||
|
||||
- name: build python exe
|
||||
include_tasks: build_py_bin.yaml
|
||||
include_tasks: python_service.yaml
|
||||
|
||||
#- name: set up nssm service
|
||||
# include_tasks: nssm.yaml
|
||||
- name: set up nssm service
|
||||
include_tasks: nssm.yaml
|
||||
|
||||
|
||||
|
||||
...
|
||||
@ -5,9 +5,21 @@
|
||||
name: nssm
|
||||
state: present
|
||||
|
||||
- name: Install the foo service
|
||||
- name: Install disk_api service
|
||||
community.windows.win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
name: "{{ disk_service_name }}"
|
||||
application: "{{ storage_api_root }}\\dist\\disk_service.exe"
|
||||
|
||||
- name: Set disk_api service startup auto and start
|
||||
ansible.windows.win_service:
|
||||
name: "{{ disk_service_name }}"
|
||||
start_mode: auto
|
||||
state: started
|
||||
register: disk_service_status
|
||||
|
||||
- name: Show service result
|
||||
debug:
|
||||
msg:
|
||||
- "{{ disk_service_status }}"
|
||||
|
||||
...
|
||||
40
roles/storage_api/tasks/python_service.yaml
Normal file
40
roles/storage_api/tasks/python_service.yaml
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
|
||||
- name: Create directory structure
|
||||
ansible.windows.win_file:
|
||||
path: "{{ storage_api_root }}"
|
||||
state: directory
|
||||
|
||||
- name: Stop service if running
|
||||
ansible.windows.win_service:
|
||||
name: "{{ disk_service_name }}"
|
||||
state: paused
|
||||
|
||||
- name: Copy disk_service.py
|
||||
ansible.windows.win_copy:
|
||||
src: disk_service.py
|
||||
dest: "{{ storage_api_root }}\\disk_service.py"
|
||||
|
||||
- name: install pyinstaller
|
||||
win_shell: "{{ python_venv_bin }} -m pip install pyinstaller"
|
||||
|
||||
- name: compile binary
|
||||
become: no
|
||||
win_shell: "{{ python_venv }}\\Scripts\\pyinstaller.exe -F {{ storage_api_root }}\\disk_service.py"
|
||||
args:
|
||||
chdir: "{{ storage_api_root }}"
|
||||
|
||||
- name: Open up port 5000
|
||||
community.windows.win_firewall_rule:
|
||||
name: _ansible_python_disk_service
|
||||
description: "Firewall rule to allow traffic for Disk info API"
|
||||
localport: 5000
|
||||
action: allow
|
||||
direction: in
|
||||
protocol: tcp
|
||||
state: present
|
||||
enabled: true
|
||||
|
||||
|
||||
|
||||
...
|
||||
@ -13,19 +13,31 @@
|
||||
- name: Copy requirements.txt
|
||||
ansible.windows.win_copy:
|
||||
src: requirements.txt
|
||||
dest: "{{ python_venv }}\requirements.txt"
|
||||
dest: "{{ python_venv }}\\requirements.txt"
|
||||
|
||||
- name: Create virtual environment
|
||||
win_shell: "py -m venv {{ python_venv }}"
|
||||
win_shell: "python -m venv {{ python_venv }}"
|
||||
|
||||
- name: Upgrade pip in the virtual environment
|
||||
win_shell: "{{ python_venv }}\pip install --upgrade pip"
|
||||
win_shell: "{{ python_venv_bin }} -m 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"
|
||||
win_shell: "{{ python_venv_bin }} -m pip install -r {{ python_venv }}\\requirements.txt"
|
||||
args:
|
||||
chdir: "{{ 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