ansibleansible-awxansible-toweransible-vault

Ansible AWX / Tower - Use Vault credential in playbook


In Ansible AWX I created a Vault-credential (named: user-pw). Now I want to use that password in a playbook. But it doesn't work.

I created a template, add the Vault-credential (at the credential input). In the playbook I used the variable "{{ user-pw }}" at the place where the password should be.

What am I doing wrong? How do I get the AWX Vault password in the playbook as a variable?

This is the vault credential screen: Vault credential

And this is the template screen: Template

And this is the test playbook:

---
- name: Vaulttest
  hosts: win

  tasks:
    - name: View user pw
      debug:
        msg: "{{ user-pw }}"

Thanks in advance!


Solution

  • Found it! I used custom credentials the wrong way.

    I created a complete new custom credential (under Administration - Credential Types).

    Input configuration:

    fields:
      - id: pass
        type: string
        label: password
        secret: true
    required:
      - pass
    

    Injector configuration:

    extra_vars:
      pass: '{{pass}}'
    

    Then I created the credential with the custom credential. Filled in the password.

    Use the password variable in a playbook like this:

    - name: Test
      module:
        username: testuser
        password: "{{ pass }}"
    

    At last, add the custom credential to the template.