I'm using Ansible to install and configure Red Hat OpenShift. One of the challenges I'm currently facing is with setting up LDAP auth using a playbook. I need to add the following variable to the Ansible inventory file -

LDAP auth

openshift_master_identity_providers=[{'name': 'idm-ldap', 'challenge': 'true', 'login': 'true', 'kind': 'LDAPPasswordIdentityProvider', 'attributes': {'id': ['dn'], 'email': ['mail'], 'name': ['cn'], 'preferredUsername': ['uid']}, 'bindDN': '"uid=<...>-bind,cn=users,cn=accounts,dc=<...>-01-<...>,dc=svcs,dc=<...>,dc=com"', 'bindPassword': {'file': '/etc/origin/master/artifacts/<...>.encrypted', 'keyFile': '/etc/origin/master/artifacts/<...>.key'}, 'ca': '/etc/origin/master/artifacts/<...>.crt', 'insecure': 'false', 'url': '"ldaps://<...>.<...>-<...>-<...>.<...>.<...>.com:<...>/ou=users,dc=example,dc=com?uid"'}]*

As this playbook is going to be used across different environments, I'd really like to be able to use the current hostname fact of the ansible host at playbook runtime as a variable to substitute for the value of url': '"ldaps://etc".

Is this possible? I've done a lot of searching but can't find any way of doing this?


You can insert a variable inside of a variable string using jinja2 the same as you do inside playbooks and task files (using double curly braces inside of double quotes):


myvar="{{ ansible_fqdn }}"


myvar: "{{ ansible_fqdn }}"

Applied specifically to your example:

openshift_master_identity_providers="[{'name': 'idm-ldap', 'challenge': 'true', 'login': 'true', 'kind': 'LDAPPasswordIdentityProvider', 'attributes': {'id': ['dn'], 'email': ['mail'], 'name': ['cn'], 'preferredUsername': ['uid']}, 'bindDN': '"uid=-bind,cn=users,cn=accounts,dc=-01-,dc=svcs,dc=,dc=com"', 'bindPassword': {'file': '/etc/origin/master/artifacts/.encrypted', 'keyFile': '/etc/origin/master/artifacts/.key'}, 'ca': '/etc/origin/master/artifacts/.crt', 'insecure': 'false', 'url': 'ldaps://{{ ansible_fqdn }}:/ou=users,dc=example,dc=com?uid'}]"

Note that the entire variable value has double quotes around it. I'm assuming this is the intended behavior, otherwise you would be better off using YAML to build out a more complex dictionary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.