fixup-vars5

Dustin 2020-03-16 21:17:41 -05:00
parent 6eecdb5ccb
commit e8d1c02427
1 changed files with 43 additions and 12 deletions

View File

@ -1,4 +1,4 @@
def call(rw_pattern, stages) { def call(rw_limit, stages) {
properties([ properties([
pipelineTriggers([cron('H H * * *')]) pipelineTriggers([cron('H H * * *')])
]) ])
@ -15,9 +15,9 @@ def call(rw_pattern, stages) {
withEnv(["KRB5CCNAME=${WORKSPACE}/.krb5cc"]) { withEnv(["KRB5CCNAME=${WORKSPACE}/.krb5cc"]) {
stageKinit() stageKinit()
try { try {
stageRemountRW(rw_pattern) stageRemountRW(rw_limit)
generateStages(stages) generateStages(stages)
stageRemountRO(rw_pattern) stageRemountRO(rw_limit)
} catch (err) { } catch (err) {
postFailure(err) postFailure(err)
} finally { } finally {
@ -32,14 +32,32 @@ def call(rw_pattern, stages) {
def stageKinit() { def stageKinit() {
stage('kinit') { stage('kinit') {
echo 'kinit' withCredentials([file(
credentialsId: 'keytab-jenkins@pyrocufflink.blue',
variable: 'KEYTAB'
)]) {
sh 'kinit -kt "${KEYTAB}" jenkins@PYROCUFFLINK.BLUE'
}
withCredentials([file(
credentialsId: 'vault-jenkins@pyrocufflink.blue',
variable: 'SUDO_PASS_FILE'
)]) {
sh 'ln -s "${SUDO_PASS_FILE}" group_vars/pyrocufflink/sudo-pass'
}
} }
} }
def stageRemountRW(rw_pattern) { def stageRemountRW(limit) {
stage('Remount R/W') { stage('Remount R/W') {
echo 'Remount R/W' ansiblePlaybook \
playbook: 'remount.yml',
limit: limit,
become: true,
vaultCredentialsId: 'ansible-vault',
extraVars: [
remount_state: 'rw',
]
} }
} }
@ -47,23 +65,36 @@ def generateStages(stages) {
stages.each { name, playbooks -> stages.each { name, playbooks ->
stage(name) { stage(name) {
playbooks.each { playbook -> playbooks.each { playbook ->
echo playbook ansiblePlaybook \
playbook: playbook,
become: true,
vaultCredentialsId: 'ansible-vault',
extras: '--diff'
} }
} }
} }
} }
def stageRemountRO(rw_pattern) { def stageRemountRO(limit) {
stage('Remount R/O') { stage('Remount R/O') {
echo 'Remount R/O' ansiblePlaybook \
playbook: 'remount.yml',
limit: limit,
become: true,
vaultCredentialsId: 'ansible-vault',
extras: '--diff'
} }
} }
def postCleanup() { def postCleanup() {
echo 'Cleanup' sh 'kdestroy'
sh 'find . -name sudo-pass -delete'
} }
def postFailure(err) { def postFailure(err) {
currentBuild.result = 'FAILURE' emailext \
echo "${err}" to: 'gyrfalcon@ebonfire.com',
subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT'
error err
} }