--- # Ported from community.general tests/integration/targets/keycloak_user_federation # Tests full LDAP user federation lifecycle: create, idempotency (with masked credentials), # update with mappers, delete, delete-absent, and create-with-mappers-in-one-step. - name: Load user federation test variables ansible.builtin.include_vars: file: vars.yml - name: Create new user federation middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: secret searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false register: result - name: Assert user federation created ansible.builtin.assert: that: - result is changed - result.existing == {} - result.end_state.name == federation - name: Create new user federation in admin realm middleware_automation.keycloak.keycloak_user_federation: realm: "{{ auth_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: secret searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false register: result - name: Assert user federation created (admin realm) ansible.builtin.assert: that: - result is changed - result.existing == {} - result.end_state.name == federation - name: Update existing user federation (no change) middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: "**********" searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false register: result - name: Assert user federation unchanged ansible.builtin.assert: that: - result is not changed - result.existing != {} - result.existing.name == federation - result.end_state != {} - result.end_state.name == federation - name: Update existing user federation (no change, admin realm) middleware_automation.keycloak.keycloak_user_federation: realm: "{{ auth_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: "**********" searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false register: result - name: Assert user federation unchanged (admin realm) ansible.builtin.assert: that: - result is not changed - result.existing != {} - result.existing.name == federation - result.end_state != {} - result.end_state.name == federation - name: Update existing user federation (with change) middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: "**********" searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false mappers: - name: "username" providerId: "user-attribute-ldap-mapper" config: ldap.attribute: ldap_user user.model.attribute: usr read.only: true - name: "full name" providerId: "full-name-ldap-mapper" providerType: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper" config: ldap.full.name.attribute: cn read.only: true write.only: false register: result - name: Assert user federation created ansible.builtin.assert: that: - result is changed - result.existing != {} - result.existing.name == federation - result.end_state != {} - result.end_state.name == federation - name: Delete existing user federation middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: absent register: result - name: Assert user federation deleted ansible.builtin.assert: that: - result is changed - result.existing != {} - result.end_state == {} - name: Delete absent user federation middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: absent register: result - name: Assert user federation unchanged ansible.builtin.assert: that: - result is not changed - result.existing == {} - result.end_state == {} - name: Create new user federation together with mappers middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: present provider_id: ldap provider_type: org.keycloak.storage.UserStorageProvider config: enabled: true priority: 0 fullSyncPeriod: -1 changedSyncPeriod: -1 cachePolicy: DEFAULT batchSizeForSync: 1000 editMode: READ_ONLY importEnabled: true syncRegistrations: false vendor: other usernameLDAPAttribute: uid rdnLDAPAttribute: uid uuidLDAPAttribute: entryUUID userObjectClasses: "inetOrgPerson, organizationalPerson" connectionUrl: "ldaps://ldap.example.com:636" usersDn: "ou=Users,dc=example,dc=com" authType: simple bindDn: cn=directory reader bindCredential: secret searchScope: 1 validatePasswordPolicy: false trustEmail: false useTruststoreSpi: "ldapsOnly" connectionPooling: true pagination: true allowKerberosAuthentication: false useKerberosForPasswordAuthentication: false debug: false mappers: - name: "username" providerId: "user-attribute-ldap-mapper" config: ldap.attribute: ldap_user user.model.attribute: usr read.only: true - name: "full name" providerId: "full-name-ldap-mapper" providerType: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper" config: ldap.full.name.attribute: cn read.only: true write.only: false register: result - name: Assert user federation created ansible.builtin.assert: that: - result is changed - result.existing == {} - result.end_state.name == federation - name: Clean up - delete user federation middleware_automation.keycloak.keycloak_user_federation: realm: "{{ ephemeral_realm }}" name: "{{ federation }}" state: absent - name: Clean up - delete user federation (admin realm) middleware_automation.keycloak.keycloak_user_federation: realm: "{{ auth_realm }}" name: "{{ federation }}" state: absent