fix job run

This commit is contained in:
reqwizz 2024-11-17 19:10:08 +03:00
parent 2f21245787
commit 55ffb7055c
4 changed files with 34 additions and 27 deletions

40
ansible/Jenkinsfile vendored
View File

@ -18,7 +18,7 @@ pipeline {
string(name: 'ADDITIONAL_CONTENT_SITEB_H2', defaultValue: 'Новое сообщение для SiteB', description: 'Дополнительный <h2> контент для SiteB')
string(name: 'ADDITIONAL_CONTENT_SITEB_P', defaultValue: 'Дополнительный параграф для SiteB', description: 'Дополнительный <p> контент для SiteB')
string(name: 'ADDITIONAL_CONTENT_ALL_H2', defaultValue: 'Новое сообщение для всех сайтов', description: 'Дополнительный <h2> контент для всех сайтов')
string(name: 'ADDITIONAL_CONTENT_ALL_P', defaultValue: 'Дополнительный параграф для всех сайтов', description: 'Дополнительный <p> контент для всех сайтов')
}
@ -49,39 +49,37 @@ pipeline {
steps {
script {
def selectedHosts
def extraVars = [
ansible_ssh_private_key_file: env.DECYPTED_KEY_FILE
]
switch(params.DEPLOY_TARGET) {
case 'SiteA':
selectedHosts = 'SiteA,proxy'
extraVars.siteA_h2 = params.ADDITIONAL_CONTENT_SITEA_H2
extraVars.siteA_p = params.ADDITIONAL_CONTENT_SITEA_P
extraVars.siteB_h2 = null
extraVars.siteB_p = null
break
case 'SiteB':
selectedHosts = 'SiteB,proxy'
extraVars.siteB_h2 = params.ADDITIONAL_CONTENT_SITEB_H2
extraVars.siteB_p = params.ADDITIONAL_CONTENT_SITEB_P
extraVars.siteA_h2 = null
extraVars.siteA_p = null
break
case 'All':
selectedHosts = 'SiteA,SiteB,proxy'
extraVars.siteA_h2 = params.ADDITIONAL_CONTENT_ALL_H2
extraVars.siteA_p = params.ADDITIONAL_CONTENT_ALL_P
extraVars.siteB_h2 = params.ADDITIONAL_CONTENT_ALL_H2
extraVars.siteB_p = params.ADDITIONAL_CONTENT_ALL_P
break
default:
error "Неизвестный DEPLOY_TARGET: ${params.DEPLOY_TARGET}"
}
def extraVars = [
ansible_ssh_private_key_file: env.DECYPTED_KEY_FILE
]
if (params.DEPLOY_TARGET == 'All') {
extraVars.siteA_h2 = params.ADDITIONAL_CONTENT_ALL_H2
extraVars.siteA_p = params.ADDITIONAL_CONTENT_ALL_P
extraVars.siteB_h2 = params.ADDITIONAL_CONTENT_ALL_H2
extraVars.siteB_p = params.ADDITIONAL_CONTENT_ALL_P
} else {
if (params.DEPLOY_TARGET == 'SiteA' || params.DEPLOY_TARGET == 'All') {
extraVars.siteA_h2 = params.ADDITIONAL_CONTENT_SITEA_H2
extraVars.siteA_p = params.ADDITIONAL_CONTENT_SITEA_P
}
if (params.DEPLOY_TARGET == 'SiteB' || params.DEPLOY_TARGET == 'All') {
extraVars.siteB_h2 = params.ADDITIONAL_CONTENT_SITEB_H2
extraVars.siteB_p = params.ADDITIONAL_CONTENT_SITEB_P
}
}
extraVars = extraVars.findAll { key, value -> value != null }
ansiblePlaybook(
playbook: 'ansible/playbook.yml',
@ -109,4 +107,4 @@ pipeline {
echo 'Deployment failed. Please check the logs for more details.'
}
}
}
}

View File

@ -1,3 +1,9 @@
siteA_h2: "Дефолтный заголовок H2 для SiteA"
siteA_p: "Дефолтный параграф для SiteA"
siteB_h2: "Дефолтный заголовок H2 для SiteB"
siteB_p: "Дефолтный параграф для SiteB"
siteA:
site_title: "SiteA - Добро пожаловать"
site_h1: "Добро пожаловать на SiteA"
@ -16,4 +22,4 @@ siteB:
proxy:
proxy_domain: "proxy.example.com"
proxy_ip: "192.168.0.63"
proxy_ip: "192.168.0.63"

View File

@ -31,4 +31,4 @@
- name: Reload Nginx
systemd:
name: nginx
state: reloaded
state: reloaded

View File

@ -1,7 +1,10 @@
upstream backend {
{% for server in upstream_servers %}
server {{ server }} max_fails=1 fail_timeout=10s;
{% endfor %}
{% if siteA.site_ip %}
server {{ siteA.site_ip }} max_fails=1 fail_timeout=10s;
{% endif %}
{% if siteB.site_ip %}
server {{ siteB.site_ip }} max_fails=1 fail_timeout=10s;
{% endif %}
}
server {
@ -34,4 +37,4 @@ server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}