Import config with source, import ansible template
This commit is contained in:
parent
7fde80d3d6
commit
489ba8d64c
|
@ -4,63 +4,10 @@
|
||||||
## description : A vm deployment
|
## description : A vm deployment
|
||||||
## usage : ./upgradevm.sh vmname ram restart
|
## usage : ./upgradevm.sh vmname ram restart
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Bash color ##########################################
|
|
||||||
# Set colors
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[00;32m'
|
|
||||||
YELLOW='\033[00;33m'
|
|
||||||
BLUE='\033[00;34m'
|
|
||||||
PURPLE='\033[00;35m'
|
|
||||||
CYAN='\033[00;36m'
|
|
||||||
LIGHTGRAY='\033[00;37m'
|
|
||||||
LRED='\033[01;31m'
|
|
||||||
LGREEN='\033[01;32m'
|
|
||||||
LYELLOW='\033[01;33m'
|
|
||||||
LBLUE='\033[01;34m'
|
|
||||||
LPURPLE='\033[01;35m'
|
|
||||||
LCYAN='\033[01;36m'
|
|
||||||
WHITE='\033[01;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.exemple"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.exemple"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
|
|
||||||
ZABBIX_USER="user"
|
|
||||||
ZABBIX_PASS=""
|
|
||||||
ZABBIX_SERVER="zabbix.tld"
|
|
||||||
ZABBIX_API="https://${ZABBIX_SERVER}/api_jsonrpc.php"
|
|
||||||
# First hostgroup of vm
|
|
||||||
ZABBIX_HOSTGROUPID1=2
|
|
||||||
# second hostgroup of vm
|
|
||||||
ZABBIX_HOSTGROUPID2=15
|
|
||||||
# First template of vm
|
|
||||||
ZABBIX_TEMPLATEID=10001
|
|
||||||
|
|
||||||
# Ansible path to run postinstall script
|
|
||||||
ASIBLE_PATH="/home/ansible/Ansible"
|
|
||||||
|
|
||||||
RUDDER_API_TOKEN=""
|
|
||||||
RUDDER_SRV="https://rudder.exemple"
|
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
|
@ -93,9 +40,20 @@ do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
info "Stopping VM"
|
info "Stopping VM"
|
||||||
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}/status/shutdown" &> /dev/null
|
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}/status/shutdown" &> /dev/null
|
||||||
|
|
||||||
|
RUNNING=$(curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X GET "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}/status/current" | jq --raw-output '.data.status')
|
||||||
|
while [ ${RUNNING} == "running" ]
|
||||||
|
do
|
||||||
|
sleep 5
|
||||||
|
RUNNING=$(curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X GET "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}/status/current" | jq --raw-output '.data.status')
|
||||||
|
done
|
||||||
|
|
||||||
|
info "Remove host from Proxmox"
|
||||||
|
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X DELETE "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}" &> /dev/null
|
||||||
|
|
||||||
info "Get token for Zabbix"
|
info "Get token for Zabbix"
|
||||||
ZABBIX_AUTH_TOKEN=$(curl -s -X POST -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method":"user.login","params":{"user":"'${ZABBIX_USER}'","password":"'${ZABBIX_PASS}'"},"auth": null,"id":0}' ${ZABBIX_API} | jq --raw-output '.result')
|
ZABBIX_AUTH_TOKEN=$(curl -s -X POST -H "Content-Type: application/json-rpc" -d '{"jsonrpc": "2.0","method":"user.login","params":{"user":"'${ZABBIX_USER}'","password":"'${ZABBIX_PASS}'"},"auth": null,"id":0}' ${ZABBIX_API} | jq --raw-output '.result')
|
||||||
|
|
||||||
|
@ -119,9 +77,10 @@ curl -s -X DELETE -H 'Content-Type: application/json' -H "X-API-Token: ${RUDDER_
|
||||||
info "Remove host from Netbox"
|
info "Remove host from Netbox"
|
||||||
clusterid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${nodename}" | jq --raw-output '.results[0].cluster.id')
|
clusterid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${nodename}" | jq --raw-output '.results[0].cluster.id')
|
||||||
deviceid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/?name=${VMNAME}" | jq --raw-output ".results[0].id")
|
deviceid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/?name=${VMNAME}" | jq --raw-output ".results[0].id")
|
||||||
|
interfaceid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/interfaces/?name=eth0&virtual_machine=${VMNAME}" | jq --raw-output ".results[0].id")
|
||||||
|
ipid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/ipam/ip-addresses/?interface_id=${interfaceid}" | jq --raw-output ".results[0].id")
|
||||||
|
curl -s -X DELETE -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" "${NETBOX_URL}${NETBOX_API_PATH}/ipam/ip-addresses/${ipid}/" &> /dev/null
|
||||||
|
curl -s -X DELETE -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/interfaces/${interfaceid}/" &> /dev/null
|
||||||
curl -s -X DELETE -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/${deviceid}/" &> /dev/null
|
curl -s -X DELETE -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/${deviceid}/" &> /dev/null
|
||||||
|
|
||||||
info "Remove host from Proxmox"
|
|
||||||
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X DELETE "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/${VMID}" &> /dev/null
|
|
||||||
|
|
||||||
info "Ending"
|
info "Ending"
|
||||||
|
|
72
deployvm.sh
72
deployvm.sh
|
@ -4,61 +4,10 @@
|
||||||
## description : A vm deployment
|
## description : A vm deployment
|
||||||
## usage : ./deployvm hypervisor/auto templateID/auto/None os-version vm ram cpu
|
## usage : ./deployvm hypervisor/auto templateID/auto/None os-version vm ram cpu
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Bash color ##########################################
|
|
||||||
# Set colors
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[00;32m'
|
|
||||||
YELLOW='\033[00;33m'
|
|
||||||
BLUE='\033[00;34m'
|
|
||||||
PURPLE='\033[00;35m'
|
|
||||||
CYAN='\033[00;36m'
|
|
||||||
LIGHTGRAY='\033[00;37m'
|
|
||||||
LRED='\033[01;31m'
|
|
||||||
LGREEN='\033[01;32m'
|
|
||||||
LYELLOW='\033[01;33m'
|
|
||||||
LBLUE='\033[01;34m'
|
|
||||||
LPURPLE='\033[01;35m'
|
|
||||||
LCYAN='\033[01;36m'
|
|
||||||
WHITE='\033[01;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.exemple"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.exemple"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
|
|
||||||
ZABBIX_USER="user"
|
|
||||||
ZABBIX_PASS=""
|
|
||||||
ZABBIX_SERVER="zabbix.example.fr"
|
|
||||||
ZABBIX_API="https://${ZABBIX_SERVER}/api_jsonrpc.php"
|
|
||||||
ZABBIX_HOSTGROUPID1=2
|
|
||||||
ZABBIX_HOSTGROUPID2=15
|
|
||||||
ZABBIX_TEMPLATEID=10001
|
|
||||||
|
|
||||||
ANSIBLE_PATH="/home/ansible/Ansible"
|
|
||||||
|
|
||||||
RUDDER_API_TOKEN=""
|
|
||||||
RUDDER_SRV="https://rudder.exmple"
|
|
||||||
|
|
||||||
UPGRADERAM="/home/ansible/adminscrips/upgraderam.sh"
|
|
||||||
UPGRADECPU="/home/ansible/adminscrips/upgradecpu.sh"
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
|
@ -154,7 +103,6 @@ then
|
||||||
UPID=$(curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST --data "newid=${NEWID}&format=qcow2&full=1&name=${VMNAME}" "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${VMTPLID}/clone" | jq --raw-output '.data')
|
UPID=$(curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST --data "newid=${NEWID}&format=qcow2&full=1&name=${VMNAME}" "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${VMTPLID}/clone" | jq --raw-output '.data')
|
||||||
else
|
else
|
||||||
info "Create new VM ${VMNAME}"
|
info "Create new VM ${VMNAME}"
|
||||||
#curl -s --insecure -b "PVEAuthCookie=${PROXMOX_TOKEN}" -x POST --data '{"node": "'${HYPERVISOR}'", "vmid": '${NEWID}', "format": "qcow2", "full": true, "name": "'${VMNAME}'"}' "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${VMTPLID}/clone"
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -186,15 +134,13 @@ GATEWAY=$(echo ${GATEWAY} | cut -d'/' -f1)
|
||||||
info "Encode ${ADDRESS}"
|
info "Encode ${ADDRESS}"
|
||||||
ENCODEADDRESS=$(echo ${ADDRESS} | sed "s@/@%2F@g")
|
ENCODEADDRESS=$(echo ${ADDRESS} | sed "s@/@%2F@g")
|
||||||
info "Configure ${VMNAME}"
|
info "Configure ${VMNAME}"
|
||||||
${UPGRADERAM} ${VMNAME} ${RAM}
|
|
||||||
${UPGRADECPU} ${VMNAME} ${CPU}
|
|
||||||
curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X PUT -d "ipconfig0=ip%3D${ENCODEADDRESS}%2Cgw%3D${GATEWAY}" "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${NEWID}/config" &> /dev/null
|
curl -s --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X PUT -d "ipconfig0=ip%3D${ENCODEADDRESS}%2Cgw%3D${GATEWAY}" "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${NEWID}/config" &> /dev/null
|
||||||
|
|
||||||
info "Get Netbox cluster ID"
|
info "Get Netbox cluster ID"
|
||||||
CLUSTERID=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${HYPERVISOR}" | jq --raw-output '.results[0].cluster.id')
|
CLUSTERID=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${HYPERVISOR}" | jq --raw-output '.results[0].cluster.id')
|
||||||
|
|
||||||
info "Add vm on Netbox"
|
info "Add vm on Netbox"
|
||||||
VMID=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"name": "'${VMNAME}'", "cluster": '${CLUSTERID}', "role": 2, disk: 20}' "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/" | jq --raw-output '.id')
|
VMID=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"name": "'${VMNAME}'", "cluster": '${CLUSTERID}', "role": 2, "disk": 20}' "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/virtual-machines/" | jq --raw-output '.id')
|
||||||
|
|
||||||
info "Create interface"
|
info "Create interface"
|
||||||
INTERFACEID=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"virtual_machine": '${VMID}',"name": "eth0", "mtu": 1500, "enabled": "true"}' "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/interfaces/" | jq --raw-output ".id" )
|
INTERFACEID=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"virtual_machine": '${VMID}',"name": "eth0", "mtu": 1500, "enabled": "true"}' "${NETBOX_URL}${NETBOX_API_PATH}/virtualization/interfaces/" | jq --raw-output ".id" )
|
||||||
|
@ -202,6 +148,9 @@ INTERFACEID=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorizat
|
||||||
info "Add ip on netbox for this interface ${INTERFACEID}"
|
info "Add ip on netbox for this interface ${INTERFACEID}"
|
||||||
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"address": "'${ADDRESS}'","vrf": '${VRF}', "status": "active", "interface": '${INTERFACEID}'}' "${NETBOX_URL}${NETBOX_API_PATH}/ipam/ip-addresses/" &> /dev/null
|
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: Token ${NETBOX_TOKEN}" --data '{"address": "'${ADDRESS}'","vrf": '${VRF}', "status": "active", "interface": '${INTERFACEID}'}' "${NETBOX_URL}${NETBOX_API_PATH}/ipam/ip-addresses/" &> /dev/null
|
||||||
|
|
||||||
|
${UPGRADERAM} ${VMNAME} ${RAM}
|
||||||
|
${UPGRADECPU} ${VMNAME} ${CPU}
|
||||||
|
|
||||||
info "Starting ${VMNAME}"
|
info "Starting ${VMNAME}"
|
||||||
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${NEWID}/status/start" &> /dev/null
|
curl --insecure -H "Content-Type: application/x-www-form-urlencoded" -H "CSRFPreventionToken: ${PROXMOX_CSRF}" -b "PVEAuthCookie=${PROXMOX_TOKEN}" -X POST "${PROXMOX_HOST}/api2/json/nodes/${HYPERVISOR}/qemu/${NEWID}/status/start" &> /dev/null
|
||||||
|
|
||||||
|
@ -225,12 +174,11 @@ sleep 300
|
||||||
|
|
||||||
info "Run ansible playbook"
|
info "Run ansible playbook"
|
||||||
cd ${ANSIBLE_PATH}
|
cd ${ANSIBLE_PATH}
|
||||||
ansible-playbook -i hosts postint.yml --limit=${VMNAME}
|
ansible-playbook -i hosts ${POSTINSTALL} --limit=${VMNAME}
|
||||||
ansible-playbook -i hosts ferm.yml --limit=${VMNAME}
|
|
||||||
|
|
||||||
info "Check if ${VMNAME} is pending"
|
info "Check if ${VMNAME} is pending"
|
||||||
RESULT=$(curl -s -X GET -H 'Content-Type: application/json' -H "X-API-Token: ${RUDDER_API_TOKEN}" -H "X-API-Version: 12" ${RUDDER_SRV}/rudder/api/nodes/pending | jq --raw-output '.data.nodes | length')
|
RESULT=$(curl -s -X GET -H 'Content-Type: application/json' -H "X-API-Token: ${RUDDER_API_TOKEN}" -H "X-API-Version: 12" ${RUDDER_SRV}/rudder/api/nodes/pending | jq --raw-output '.data.nodes | length')
|
||||||
|
I=0
|
||||||
while [ "${RESULT}" -le "1" ]; do
|
while [ "${RESULT}" -le "1" ]; do
|
||||||
sleep 1
|
sleep 1
|
||||||
I=$((${I}+1))
|
I=$((${I}+1))
|
||||||
|
|
27
facts.sh
27
facts.sh
|
@ -4,28 +4,10 @@
|
||||||
## description : A Nextcloud Update
|
## description : A Nextcloud Update
|
||||||
## usage : ./nextcloud.sh
|
## usage : ./nextcloud.sh
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "[INFO] $* " | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "[WARNING] $* " | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "[ERROR] $* " | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "[FATAL] $* " | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.example"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
FACTS_FOLDER="PAHT/TO/FACT/STORE/facts"
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.example"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
info "Get token for Proxmox"
|
info "Get token for Proxmox"
|
||||||
|
@ -36,7 +18,6 @@ for nodes in $(curl -s --insecure -b "PVEAuthCookie=${PROXMOX_TOKEN}" "${PROXMOX
|
||||||
do
|
do
|
||||||
nodename=$(echo ${nodes} | base64 --decode | jq --raw-output '.node')
|
nodename=$(echo ${nodes} | base64 --decode | jq --raw-output '.node')
|
||||||
clusterid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${nodename}" | jq --raw-output '.results[0].cluster.id')
|
clusterid=$(curl -s -X GET -H "Authorization: Token ${NETBOX_TOKEN}" -H "Accept: application/json; indent=4" "${NETBOX_URL}${NETBOX_API_PATH}/dcim/devices/?name=${nodename}" | jq --raw-output '.results[0].cluster.id')
|
||||||
#for nodes in $(curl -s --insecure -b "PVEAuthCookie=${PROXMOX_TOKEN}" "${PROXMOX_HOST}/api2/json/nodes/" | jq --raw-output '.data[] | @base64')
|
|
||||||
info "Get VM"
|
info "Get VM"
|
||||||
for qemus in $(curl -s --insecure -b "PVEAuthCookie=${PROXMOX_TOKEN}" "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/" | jq --raw-output '.data[] | @base64')
|
for qemus in $(curl -s --insecure -b "PVEAuthCookie=${PROXMOX_TOKEN}" "${PROXMOX_HOST}/api2/json/nodes/${nodename}/qemu/" | jq --raw-output '.data[] | @base64')
|
||||||
do
|
do
|
||||||
|
|
46
resize.sh
46
resize.sh
|
@ -5,48 +5,10 @@
|
||||||
## description : A vm deployment
|
## description : A vm deployment
|
||||||
## usage : ./deployvm VMName resize
|
## usage : ./deployvm VMName resize
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Bash color ##########################################
|
|
||||||
# Set colors
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[00;32m'
|
|
||||||
YELLOW='\033[00;33m'
|
|
||||||
BLUE='\033[00;34m'
|
|
||||||
PURPLE='\033[00;35m'
|
|
||||||
CYAN='\033[00;36m'
|
|
||||||
LIGHTGRAY='\033[00;37m'
|
|
||||||
LRED='\033[01;31m'
|
|
||||||
LGREEN='\033[01;32m'
|
|
||||||
LYELLOW='\033[01;33m'
|
|
||||||
LBLUE='\033[01;34m'
|
|
||||||
LPURPLE='\033[01;35m'
|
|
||||||
LCYAN='\033[01;36m'
|
|
||||||
WHITE='\033[01;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.example"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.exemple"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
# Var to run postinstall
|
|
||||||
ANSIBLE_PATH=""
|
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
hostname: <VMNAME>
|
||||||
|
ip_address: <IPADDR>
|
||||||
|
prometheus_exporter_listen_address: <IPADDR>
|
||||||
|
|
||||||
|
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||||
|
|
||||||
|
description: Serveur d'application
|
||||||
|
|
||||||
|
# NTP
|
||||||
|
ntp_servers:
|
||||||
|
- 0.pool.ntp.org
|
||||||
|
- 1.pool.ntp.org
|
||||||
|
- 2.pool.ntp.org
|
||||||
|
|
||||||
|
rudder_server: 10.10.11.15
|
||||||
|
|
||||||
|
ferm_rules:
|
||||||
|
z_98_prometheus:
|
||||||
|
- chain: INPUT
|
||||||
|
domains:
|
||||||
|
- ip
|
||||||
|
rules:
|
||||||
|
- rule: "proto tcp saddr 10.0.2.3 dport (9113) ACCEPT;"
|
||||||
|
comment: "Allow Prometheus server access to Prometheus exporter"
|
|
@ -4,46 +4,10 @@
|
||||||
## description : A vm deployment
|
## description : A vm deployment
|
||||||
## usage : ./upgradecpu.sh vmname cpu restart
|
## usage : ./upgradecpu.sh vmname cpu restart
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Bash color ##########################################
|
|
||||||
# Set colors
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[00;32m'
|
|
||||||
YELLOW='\033[00;33m'
|
|
||||||
BLUE='\033[00;34m'
|
|
||||||
PURPLE='\033[00;35m'
|
|
||||||
CYAN='\033[00;36m'
|
|
||||||
LIGHTGRAY='\033[00;37m'
|
|
||||||
LRED='\033[01;31m'
|
|
||||||
LGREEN='\033[01;32m'
|
|
||||||
LYELLOW='\033[01;33m'
|
|
||||||
LBLUE='\033[01;34m'
|
|
||||||
LPURPLE='\033[01;35m'
|
|
||||||
LCYAN='\033[01;36m'
|
|
||||||
WHITE='\033[01;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.example"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.example"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
|
|
|
@ -4,46 +4,10 @@
|
||||||
## description : A vm deployment
|
## description : A vm deployment
|
||||||
## usage : ./upgradevm.sh vmname ram restart
|
## usage : ./upgradevm.sh vmname ram restart
|
||||||
|
|
||||||
## Bash strict mode ####################################
|
## Import require config ##############################
|
||||||
set -o errexit # abort on nonzero exitstatus
|
source utils/config
|
||||||
set -o nounset # abort on unbound variable
|
source utils/color
|
||||||
set -o pipefail # don't hide errors within pipes
|
source utils/logger
|
||||||
|
|
||||||
## Bash color ##########################################
|
|
||||||
# Set colors
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[00;32m'
|
|
||||||
YELLOW='\033[00;33m'
|
|
||||||
BLUE='\033[00;34m'
|
|
||||||
PURPLE='\033[00;35m'
|
|
||||||
CYAN='\033[00;36m'
|
|
||||||
LIGHTGRAY='\033[00;37m'
|
|
||||||
LRED='\033[01;31m'
|
|
||||||
LGREEN='\033[01;32m'
|
|
||||||
LYELLOW='\033[01;33m'
|
|
||||||
LBLUE='\033[01;34m'
|
|
||||||
LPURPLE='\033[01;35m'
|
|
||||||
LCYAN='\033[01;36m'
|
|
||||||
WHITE='\033[01;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
## Logs ################################################
|
|
||||||
readonly SCRIPTNAME="$(basename "$0")"
|
|
||||||
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
|
||||||
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
|
||||||
########################################################
|
|
||||||
|
|
||||||
## Define variables ####################################
|
|
||||||
NETBOX_URL="https://netbox.example"
|
|
||||||
NETBOX_API_PATH="/api"
|
|
||||||
NETBOX_TOKEN=""
|
|
||||||
|
|
||||||
PROXMOX_HOST="https://proxmox.example"
|
|
||||||
PROXMOX_USER="user"
|
|
||||||
PROXMOX_PASSWORD=""
|
|
||||||
|
|
||||||
#######################################################
|
#######################################################
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
## Bash color ##########################################
|
||||||
|
# Set colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[00;32m'
|
||||||
|
YELLOW='\033[00;33m'
|
||||||
|
BLUE='\033[00;34m'
|
||||||
|
PURPLE='\033[00;35m'
|
||||||
|
CYAN='\033[00;36m'
|
||||||
|
LIGHTGRAY='\033[00;37m'
|
||||||
|
LRED='\033[01;31m'
|
||||||
|
LGREEN='\033[01;32m'
|
||||||
|
LYELLOW='\033[01;33m'
|
||||||
|
LBLUE='\033[01;34m'
|
||||||
|
LPURPLE='\033[01;35m'
|
||||||
|
LCYAN='\033[01;36m'
|
||||||
|
WHITE='\033[01;37m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
## Bash strict mode ####################################
|
||||||
|
# Theses setting are usefull for keep in safe you're infrastructure
|
||||||
|
set -o errexit # abort on nonzero exitstatus
|
||||||
|
set -o nounset # abort on unbound variable
|
||||||
|
set -o pipefail # don't hide errors within pipes
|
||||||
|
|
||||||
|
## Define variables ####################################
|
||||||
|
# For each token, give all right of you're account (read, write, put, patch, delete, clone (proxmox) etc...)
|
||||||
|
NETBOX_URL="https://netbox.exemple"
|
||||||
|
NETBOX_API_PATH="/api"
|
||||||
|
NETBOX_TOKEN=""
|
||||||
|
|
||||||
|
PROXMOX_HOST="https://proxmox.example:8006"
|
||||||
|
PROXMOX_USER="user"
|
||||||
|
PROXMOX_PASSWORD=""
|
||||||
|
|
||||||
|
ZABBIX_USER="user"
|
||||||
|
ZABBIX_PASS=""
|
||||||
|
ZABBIX_SERVER="zabbix.example"
|
||||||
|
ZABBIX_API="https://${ZABBIX_SERVER}/api_jsonrpc.php"
|
||||||
|
ZABBIX_HOSTGROUPID1=2
|
||||||
|
ZABBIX_HOSTGROUPID2=15
|
||||||
|
ZABBIX_TEMPLATEID=10001
|
||||||
|
|
||||||
|
# This variable is usefull to run postinstall playbook
|
||||||
|
ANSIBLE_PATH="/home/ansible/Ansible"
|
||||||
|
POSTINSTALL="postint.yml ferm.yml"
|
||||||
|
|
||||||
|
RUDDER_API_TOKEN=""
|
||||||
|
RUDDER_SRV="https://rudder.example"
|
||||||
|
|
||||||
|
UPGRADERAM="/your/git/path/management-script/upgraderam.sh"
|
||||||
|
UPGRADECPU="/your/git/path/management-script/upgradecpu.sh"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
## Logs ################################################
|
||||||
|
readonly SCRIPTNAME="$(basename "$0")"
|
||||||
|
info() { echo -e "${LBLUE}[INFO] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
||||||
|
warning() { echo -e "${YELLOW}[WARNING] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
||||||
|
error() { echo -e "${LRED}[ERROR] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; }
|
||||||
|
fatal() { echo -e "${RED}[FATAL] $* ${NC}" | logger --tag "${SCRIPTNAME}" --stderr ; exit 1 ; }
|
Loading…
Reference in New Issue