---

- name: generate new secret key
  command: makepasswd
    --string=abcdefghijklmnopqrstuvwxyz0123456789\@\%\^\&\*\(\-\_\=\+\)
    --chars=50
  register: _

- set_fact: >
    django_secret_key="{{_.stdout}}"

- name: determine database engine
  set_fact: >
    db_engine="{{ db_engine_postgis }}"
  when: enable_postgis

- name: configure django secret settings
  template: >
    src="secret.py.j2"
    dest="{{ install_path }}/{{ service_name }}/{{ secret_settings }}"
    owner={{ service_user }}
    group={{ service_group }}
    mode=0644
    backup=yes
  notify:
    - restart service group

- name: configure django local settings
  template: >
    src="local.py.j2"
    dest="{{ install_path }}/{{ service_name }}/{{ local_settings }}"
    owner={{ service_user }}
    group={{ service_group }}
    mode=0644
    backup=yes
  notify:
    - restart service group

- name: add DJANGO_SETTINGS_MODULE to .bashrc
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="export DJANGO_SETTINGS_MODULE={{ django_settings_module }}"
    state=present

---

- name: generate django_secret_key
  set_fact: >
    django_secret_key="{{ lookup('password', '/tmp/foo chars=ascii_letters,digits length=50') }}"

- name: determine database engine
  set_fact: >
    db_engine="{{ db_engine_postgis }}"
  when: enable_postgis

- name: configure django secret settings
  template: >
    src="secret.py.j2"
    dest="{{ install_path }}/{{ service_name }}/{{ secret_settings }}"
    owner={{ service_user }}
    group={{ service_group }}
    mode=0644
    backup=yes
  notify:
    - restart service group

- name: configure django local settings
  template: >
    src="local.py.j2"
    dest="{{ install_path }}/{{ service_name }}/{{ local_settings }}"
    owner={{ service_user }}
    group={{ service_group }}
    mode=0644
    backup=yes
  notify:
    - restart service group

- name: add DJANGO_SETTINGS_MODULE to .bashrc
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="export DJANGO_SETTINGS_MODULE={{ django_settings_module }}"
    state=present

Replace makepasswd with ansible internal generator
Replace makepasswd with ansible internal generator
