39 lines
1.7 KiB
Groovy
39 lines
1.7 KiB
Groovy
|
pipeline {
|
||
|
agent any
|
||
|
|
||
|
parameters {
|
||
|
string(name: 'TARGET_IP', defaultValue: '192.168.0.72', description: 'IP адрес машины для установки PostgreSQL')
|
||
|
string(name: 'DB_USER', defaultValue: 'myuser', description: 'Имя пользователя для базы данных PostgreSQL')
|
||
|
string(name: 'DB_NAME', defaultValue: 'mydatabase', description: 'Имя базы данных PostgreSQL')
|
||
|
}
|
||
|
|
||
|
environment {
|
||
|
ANSIBLE_HOST_KEY_CHECKING = 'False'
|
||
|
}
|
||
|
|
||
|
stages {
|
||
|
stage('Run Ansible Playbook') {
|
||
|
steps {
|
||
|
withCredentials([usernamePassword(credentialsId: 'postgres_password_credential', usernameVariable: 'SSH_USER', passwordVariable: 'POSTGRES_PASSWORD'),
|
||
|
usernamePassword(credentialsId: 'sqlpass', usernameVariable: 'SQL_USER', passwordVariable: 'SQL_PASSWORD')]) {
|
||
|
script {
|
||
|
|
||
|
writeFile file: '/ansiblesql/hosts.ini', text: """
|
||
|
[postgres_servers]
|
||
|
${params.TARGET_IP} ansible_user=${SSH_USER} ansible_ssh_pass=${POSTGRES_PASSWORD} ansible_connection=ssh
|
||
|
"""
|
||
|
|
||
|
|
||
|
sh """
|
||
|
ansible-playbook -i /ansiblesql/hosts.ini /ansiblesql/install_postgresql.yml \
|
||
|
-e postgres_user=${params.DB_USER} \
|
||
|
-e postgres_password=${SQL_PASSWORD} \
|
||
|
-e postgres_db=${params.DB_NAME}
|
||
|
"""
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|