简体   繁体   中英

How to pass jenkins passwords into ansible playbook via pipeline

How to inject passwords to the build as environment variables(these are job passwords) for deployment through ansible via pipeline or dsl script

First, those job passwords should be registered as credentials inside Jenkins.

Second, you can use said file when calling your ansible-playbook command , through the Credentials Binding plugin .
See " How to use multiple credentials in withCredentials in Jenkins Pipeline "

node {
  withCredentials([
    usernamePassword(credentialsId: credsId1, usernameVariable: 'USER1', passwordVariable: 'PASS1'),
    usernamePassword(credentialsId: credsId2, usernameVariable: 'USER2', passwordVariable: 'PASS2')
    ...
  ]) {
    sh '''
      set +x
      ansible-playbook /path/to/ansible-playbook.yml -i /path/to/hosts_list -u AUTO_USER --private-key=/path/to/private-key \
      -e $USER1=$PASS1 -e $USER2=$PASS2
    '''
  }
}

Note: the file should have a JSON content, with your

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM