Reputation: 605
I have a Jenkinsfile trying to launch an Ansible playbook which references some parameters stored in an Ansible vault encrypted file.
Ansible is installed in version 2.4.0.0
Here is a snippet of my jenkins file:
withCredentials([[$class: 'StringBinding', credentialsId: 'vault_token', variable: 'VAULT_TOKEN']]) {
ansiblePlaybook(
playbook: "./ansible/playbooks/deploy.yml",
inventory: "./ansible/hosts/hosts",
credentialsId: "$VAULT_TOKEN"
}
And there is the playbook:
---
- hosts: managers
become: true
tasks:
- include_vars: ../vaults/passwords.yml
- name: Log into Docker repository
docker_login:
registry: my.registry.org
username: "{{ reg_user }}"
password: "{{ reg_password }}"
This playbooks includes the vault file containing the encrypted values. When Jenkins execute the Jenkinsfile, I get the following error: Attempting to decrypt but no vault secrets found
Why is ansible not using the credentialId i've passed to him in the Jenkinsfile and what is the good way to pass this credential?
Upvotes: 2
Views: 9263
Reputation: 410
Upvotes: 3
Reputation: 195
try the following
withCredentials([file(credentialsId: 'vault_token', variable: 'VAULT_TOKEN')]) {
ansiblePlaybook colorized: true, credentialsId: '', forks: 10, inventory: 'ansible/hosts/hosts', limit: '', playbook: 'ansible/playbooks/deploy.yml', sudoUser: null, extras: "--vault-password-file ${VAULT_TOKEN}"
}
you need to add the
extras: "--vault-password-file ${VAULT_TOKEN}"
and leave credentialsId blank.
Upvotes: 0