---
#
# edX Configuration
#
# github:     https://github.com/edx/configuration
# wiki:       https://openedx.atlassian.net/wiki/display/OpenOPS
# code style: https://openedx.atlassian.net/wiki/display/OpenOPS/Ansible+Code+Conventions
# license:    https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role oauth_client_setup
#
# Overview:
#
#
# Dependencies:
#
#
# Example play:
#
#

- name: create OAuth2 Clients
  shell: >
    {{ COMMON_BIN_DIR }}/python.edxapp {{ COMMON_BIN_DIR }}/manage.edxapp lms --settings={{ COMMON_EDXAPP_SETTINGS }}
    create_oauth2_client
    {{ item.url_root }}
    "{{ item.url_root }}/complete/edx-oidc/"
    confidential
    --client_name {{ item.name }}
    --client_id {{ item.id }}
    --client_secret {{ item.secret }}
    --trusted
    --logout_uri {{ item.logout_uri | default("") }}
    --username {{ item.username }}
  become_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  with_items: "{{ oauth_client_setup_oauth2_clients }}"
  when: item.name != 'None'
  tags: ["oauth_client_setup"]

---
#
# edX Configuration
#
# github:     https://github.com/edx/configuration
# wiki:       https://openedx.atlassian.net/wiki/display/OpenOPS
# code style: https://openedx.atlassian.net/wiki/display/OpenOPS/Ansible+Code+Conventions
# license:    https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role oauth_client_setup
#
# Overview:
#
#
# Dependencies:
#
#
# Example play:
#
#

- name: create OAuth2 Clients
  shell: >
    {{ COMMON_BIN_DIR }}/python.edxapp {{ COMMON_BIN_DIR }}/manage.edxapp lms --settings={{ COMMON_EDXAPP_SETTINGS }}
    create_oauth2_client
    {{ item.url_root }}
    "{{ item.url_root }}/complete/edx-oidc/"
    confidential
    --client_name {{ item.name }}
    --client_id {{ item.id }}
    --client_secret {{ item.secret }}
    --trusted
    --logout_uri {{ item.logout_uri | default("") }}
    {% if item.username is defined %} --username {{ item.username }} {% endif %}
  become_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  with_items: "{{ oauth_client_setup_oauth2_clients }}"
  when: item.name != 'None'
  tags: ["oauth_client_setup"]

Allow to create OAuth client without username
Allow to create OAuth client without username

Update playbooks/roles/oauth_client_setup/tasks/main.yml

Co-Authored-By: melvinsoft <melvinsoft@gmail.com>

Update playbooks/roles/oauth_client_setup/tasks/main.yml

Co-Authored-By: melvinsoft <melvinsoft@gmail.com>

try with a single task

reset the username as false

try with is defined
