I am trying to setup Jenkins job calling ansible-playbook. There is an issue with
withCredentials([file(credentialsId: 'my_vault', variable: 'VAULT_TOKEN')]){
ansiblePlaybook(
// ...
playbook: 'clusterControl.yml',
inventory: 'inventories/${env.Stand}/hosts',
extras: " ${ansible_log_level} --ssh-extra-args='-o StrictHostKeyChecking=no' --vault-password-file '${VAULT_TOKEN}'")}
clusterControl.yml has the following content:
---
- hosts: "{{ domain | default('stand') }}"
strategy: free
gather_facts: no
vars_files:
- "inventories/{{ stand }}/bh_vault.yml"
roles:
- { role: 03_clusterControl, when: ' "win" in (group_names | string) ' }
- { role: 03_clusterControl_linux, when: ' "lin" in (group_names | string) ' }
bh_vault.yml
is file encrypted with ansible-vault encrypt
with password from VAULT_TOKEN
containing these lines
bh:
ip: "ip.of.my.server"
username: "my_username"
password: "my_p@ssw0rd"
When I run it Jeninks fails with
fatal: [str-vst-was0012]: FAILED! => {"failed": true, "msg": "The field 'remote_user' has an invalid value, which includes an undefined variable. The error was: 'bh' is undefined\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'bh' is undefined"}
PLAY RECAP *********************************************************************
str-vst-was0012 : ok=0 changed=0 unreachable=0 failed=1
How to pass bh.ip to ansible?