From 55ffb7055c72c68cfc82e44ae7c72f3c8972a545 Mon Sep 17 00:00:00 2001 From: reqwizz Date: Sun, 17 Nov 2024 19:10:08 +0300 Subject: [PATCH] fix job run --- ansible/Jenkinsfile | 40 +++++++++---------- ansible/group_vars/all.yml | 8 +++- ansible/roles/nginx_proxy/tasks/main.yml | 2 +- .../roles/nginx_proxy/templates/proxy.conf.j2 | 11 +++-- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/ansible/Jenkinsfile b/ansible/Jenkinsfile index 9d3b0d9..81c9b08 100644 --- a/ansible/Jenkinsfile +++ b/ansible/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { string(name: 'ADDITIONAL_CONTENT_SITEB_H2', defaultValue: 'Новое сообщение для SiteB', description: 'Дополнительный

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

контент для SiteB') - + string(name: 'ADDITIONAL_CONTENT_ALL_H2', defaultValue: 'Новое сообщение для всех сайтов', description: 'Дополнительный

контент для всех сайтов') string(name: 'ADDITIONAL_CONTENT_ALL_P', defaultValue: 'Дополнительный параграф для всех сайтов', description: 'Дополнительный

контент для всех сайтов') } @@ -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.' } } -} +} \ No newline at end of file diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index b2a1f3e..ddb6f08 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -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" \ No newline at end of file diff --git a/ansible/roles/nginx_proxy/tasks/main.yml b/ansible/roles/nginx_proxy/tasks/main.yml index ebe481d..c26c9f9 100644 --- a/ansible/roles/nginx_proxy/tasks/main.yml +++ b/ansible/roles/nginx_proxy/tasks/main.yml @@ -31,4 +31,4 @@ - name: Reload Nginx systemd: name: nginx - state: reloaded + state: reloaded \ No newline at end of file diff --git a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 index 8aa2af2..9ebccdd 100644 --- a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 +++ b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 @@ -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; } -} +} \ No newline at end of file