Hello people:
I wonder if would be possible, somehow, to pass more than 1 credential set to a certain job template in AWX. It happens that I use ansible for creating VM templates on VMware, so I’m currently using a vCenter credential to my playbook, but also I’d like to pass another credentials for setting up the root or administrator password for the operating system VM.
Hope someone can give me some idea about how to achieve this, if there’s some way to do it.
Thanks in advance.
I handle situations like that by putting my credentials into a vault file that is part of my project - apply those credentials via groups and then have the credential for the vault file in the Alex job template
You can only pass one machine credential, but you can attach other credential types to the same template or job. You could set up a custom credential type to hold anything you want to add. I usually add credentials that contain values for notification modules, like Slack or API credentials that include tokens and/or URLs.
Best of luck,
Dave
Hi:
You can only pass one machine credential, but you can attach other credential types to the same template or job. You could set up a custom credential type to hold anything you want to add. I usually add credentials that contain values for notification modules, like Slack or API credentials that include tokens and/or URLs.
OK, great, I can create custom credentials, but how do I reference those custom credentials in my playbook invoked through AWX? I haven’t created any custom credential yet, but I guess I would pass it as argument in the same way as a Network credential, am I right?
Add credential values to a job as extra_vars using the injector configuration of your custom credential type. For example, I create a custom credential type like this:
CREDENTIAL TYPE
Slack Token
INPUT CONFIGURATION
fields:
- id: token
type: string
required:
- token
INJECTOR CONFIGURATION
extra_vars:
slack_token: ‘{{ token }}’
Then, create a credential with that type and attach it to your template, in addition to a machine credential. Then, in the playbook, I can reference the variable “slack_token” as if I set it in the extra_vars field of the template:
- name: notify-slack
delegate_to: localhost
become: no
slack:
token: "{{ **slack_token** }}"
channel: "{{ slack_channel | default('#ansible') }}"
username: "{{ slack_user | default('Enterprise-Ansible') }}"
msg: "{{ slack_message }}"
Ooh I got it, thank you so much. I’m going to test this to see how it works.
Thanks again everyone!