2024-11-12 20:14:17 +00:00
|
|
|
pipeline {
|
|
|
|
agent any
|
|
|
|
|
|
|
|
environment {
|
|
|
|
ANSIBLE_HOST_KEY_CHECKING = 'false'
|
|
|
|
VAULT_PASSWORD = credentials('vault_password')
|
|
|
|
}
|
|
|
|
|
|
|
|
parameters {
|
2024-11-12 20:43:48 +00:00
|
|
|
string(name: 'ADDITIONAL_CONTENT_SITEA_H2', defaultValue: 'Новое сообщение для SiteA', description: 'Additional <h2> content for SiteA')
|
|
|
|
string(name: 'ADDITIONAL_CONTENT_SITEA_P', defaultValue: 'Дополнительный параграф для SiteA', description: 'Additional <p> content for SiteA')
|
|
|
|
string(name: 'ADDITIONAL_CONTENT_SITEB_H2', defaultValue: 'Новое сообщение для SiteB', description: 'Additional <h2> content for SiteB')
|
|
|
|
string(name: 'ADDITIONAL_CONTENT_SITEB_P', defaultValue: 'Дополнительный параграф для SiteB', description: 'Additional <p> content for SiteB')
|
2024-11-12 20:14:17 +00:00
|
|
|
}
|
2024-11-12 20:43:48 +00:00
|
|
|
|
2024-11-12 20:14:17 +00:00
|
|
|
stages {
|
|
|
|
stage('Decrypt SSH Key') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
def tempDir = '/tmp/' + UUID.randomUUID().toString()
|
|
|
|
env.TEMP_DIR = tempDir
|
|
|
|
sh "mkdir -p ${tempDir}"
|
|
|
|
|
|
|
|
def decryptedKeyFile = "${tempDir}/id_ed25519"
|
|
|
|
def vaultPassFile = "${tempDir}/vault_pass"
|
|
|
|
|
|
|
|
writeFile file: vaultPassFile, text: VAULT_PASSWORD
|
|
|
|
|
|
|
|
sh """
|
|
|
|
ansible-vault decrypt ./ansible/id_ed25519_vault --output=${decryptedKeyFile} --vault-password-file=${vaultPassFile}
|
|
|
|
"""
|
|
|
|
|
|
|
|
env.DECYPTED_KEY_FILE = decryptedKeyFile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Deploy Site') {
|
|
|
|
steps {
|
|
|
|
script {
|
2024-11-12 20:43:48 +00:00
|
|
|
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
|
|
|
|
]
|
2024-11-12 20:14:17 +00:00
|
|
|
|
|
|
|
ansiblePlaybook(
|
|
|
|
playbook: 'ansible/playbook.yml',
|
|
|
|
inventory: "ansible/inventory.yml",
|
2024-11-12 20:43:48 +00:00
|
|
|
extraVars: extraVars,
|
|
|
|
limit: 'SiteA,SiteB,proxy'
|
2024-11-12 20:14:17 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-12 20:43:48 +00:00
|
|
|
|
2024-11-12 20:14:17 +00:00
|
|
|
post {
|
|
|
|
always {
|
|
|
|
script {
|
|
|
|
if (env.TEMP_DIR) {
|
|
|
|
sh "rm -rf ${env.TEMP_DIR}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
success {
|
|
|
|
echo 'Deployment completed successfully.'
|
|
|
|
}
|
|
|
|
failure {
|
|
|
|
echo 'Deployment failed. Please check the logs for more details.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|