Jenkens integration with variables and dynamic hosts.ini file
This commit is contained in:
parent
013994211f
commit
803c80efff
@ -1,2 +0,0 @@
|
||||
[postgres_servers]
|
||||
192.168.0.72 ansible_user=root ansible_password='XSW@1qaz' ansible_connection=ssh
|
@ -3,9 +3,9 @@
|
||||
hosts: postgres_servers
|
||||
become: yes
|
||||
vars:
|
||||
postgres_user: myuser
|
||||
postgres_password: mypassword
|
||||
postgres_db: mydatabase
|
||||
postgres_user: "{{ postgres_user }}"
|
||||
postgres_password: "{{ postgres_password }}"
|
||||
postgres_db: "{{ postgres_db }}"
|
||||
tasks:
|
||||
|
||||
- name: Update zypper
|
||||
|
38
pipeline.groovy
Normal file
38
pipeline.groovy
Normal file
@ -0,0 +1,38 @@
|
||||
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}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user