From b6f55f118678d08cc7c817626990d55c04e93b29 Mon Sep 17 00:00:00 2001 From: reqwizz Date: Tue, 12 Nov 2024 23:43:48 +0300 Subject: [PATCH] fix bugs jenkinsjob --- ansible/Jenkinsfile | 35 ++++++++----------- ansible/group_vars/all.yml | 8 ++--- .../roles/nginx_proxy/templates/proxy.conf.j2 | 7 ++-- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/ansible/Jenkinsfile b/ansible/Jenkinsfile index 83b0713..7b33426 100644 --- a/ansible/Jenkinsfile +++ b/ansible/Jenkinsfile @@ -7,10 +7,12 @@ pipeline { } parameters { - choice(name: 'SITE_OPTION', choices: ['SiteA', 'SiteB', 'SiteA&B'], description: 'Select which site to deploy') - string(name: 'ADDITIONAL_CONTENT', defaultValue: 'Новое сообщение', description: 'Additional content to be included in the site') + string(name: 'ADDITIONAL_CONTENT_SITEA_H2', defaultValue: 'Новое сообщение для SiteA', description: 'Additional

content for SiteA') + string(name: 'ADDITIONAL_CONTENT_SITEA_P', defaultValue: 'Дополнительный параграф для SiteA', description: 'Additional

content for SiteA') + string(name: 'ADDITIONAL_CONTENT_SITEB_H2', defaultValue: 'Новое сообщение для SiteB', description: 'Additional

content for SiteB') + string(name: 'ADDITIONAL_CONTENT_SITEB_P', defaultValue: 'Дополнительный параграф для SiteB', description: 'Additional

content for SiteB') } - + stages { stage('Decrypt SSH Key') { steps { @@ -36,32 +38,25 @@ pipeline { stage('Deploy Site') { steps { script { - def sanitized_content = params.ADDITIONAL_CONTENT.replaceAll("'", "\\'").replaceAll('"', '\\"') - - def siteOption = params.SITE_OPTION - def targetGroups = '' - if (siteOption == 'SiteA') { - targetGroups = 'SiteA,proxy' - } else if (siteOption == 'SiteB') { - targetGroups = 'SiteB,proxy' - } else if (siteOption == 'SiteA&B') { - targetGroups = 'SiteA,SiteB,proxy' - } + def extraVars = [ + siteA_h2: params.ADDITIONAL_CONTENT_SITEA_H2, + siteA_p: params.ADDITIONAL_CONTENT_SITEA_P, + siteB_h2: params.ADDITIONAL_CONTENT_SITEB_H2, + siteB_p: params.ADDITIONAL_CONTENT_SITEB_P, + ansible_ssh_private_key_file: env.DECYPTED_KEY_FILE + ] ansiblePlaybook( playbook: 'ansible/playbook.yml', inventory: "ansible/inventory.yml", - extraVars: [ - additional_content: sanitized_content, - ansible_ssh_private_key_file: env.DECYPTED_KEY_FILE - ], - limit: targetGroups + extraVars: extraVars, + limit: 'SiteA,SiteB,proxy' ) } } } } - + post { always { script { diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 1489f3e..b2a1f3e 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -1,16 +1,16 @@ siteA: site_title: "SiteA - Добро пожаловать" site_h1: "Добро пожаловать на SiteA" - site_h2: "Секция SiteA" - site_p: "Это дополнительный параграф для SiteA." + site_h2: "{{ siteA_h2 }}" + site_p: "{{ siteA_p }}" site_domain: "siteA.example.com" site_ip: "192.168.0.61" siteB: site_title: "SiteB - Добро пожаловать" site_h1: "Добро пожаловать на SiteB" - site_h2: "Секция SiteB" - site_p: "Это дополнительный параграф для SiteB." + site_h2: "{{ siteB_h2 }}" + site_p: "{{ siteB_p }}" site_domain: "siteB.example.com" site_ip: "192.168.0.62" diff --git a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 index d848f2c..0022456 100644 --- a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 +++ b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 @@ -17,10 +17,13 @@ server { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; } location /health { - return 200 'Proxy is up'; - add_header Content-Type text/plain; + proxy_pass http://backend/health; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } \ No newline at end of file