Create 1st Admin User from CLI

uname -a

Linux asterisk 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

asterisk*CLI> core show version
Asterisk 17.2.0 built by root @ asterisk on a x86_64 running Linux on 2020-03-02 14:07:52 UTC

Hi, I am using Ansible to install Asterisk and FreePBX 15 on Ubuntu 18.04 LTS.

I would like to be able to create the first admin user account from the CLI instead of having to visit the http interface in a browser and create from there.

How can I do this?

You could Wireshark everything you do in your browser, once, then try to automate the web interaction with Ansible:

Thanks penguinpbx. I was looking for something more unattended. It would be awesome if one could pass a file containing key:values to the install. Or even just pass the first user. So you end up with a task looking like:

  • name: run scripts
    command: “./install -n --dbuser {{ mariadb_user }} --dbpass {{ mariadb_user_pass }} --adminuser {{ ast_admin_user }} --adminpass {{ ast_admin_pass }}”
    ignore_errors: yes
    chdir: /usr/src/freepbx
    when: freepbx_found.stat.exists == False

Any remaining values could then be set using the command module along with amportal syntax.

Frankly I am surprised nobody thought of it before. It is common for a number of applications to provide such or similar option where any number of settings can be passed to the install.

From bash, try:-

PASSWORDSHA1=$(echo -n seanwepassword|sha1sum|awk ‘{print $1}’)
mysql asterisk -e “INSERT INTO ampusers (username,password_sha1,sections) VALUES (‘seanwe’,’$PASSWORDSHA1’,’*’)”

1 Like

Hi dicko, thanks for the input. Just to update my solution is as follows:

- name: sh1 password
    cmd: "echo -n {{ systems_user_password }}|sha1sum|awk '{print $1}'"
  register: sha1_password

- name: add first systems user
    cmd: mysql -u{{ mariadb_user }} asterisk -e "INSERT INTO ampusers (username,password_sha1,sections) VALUES ('{{ systems_user }}','{{ sha1_password.stdout }}','*')"

- name: first wizard settings page (msm)
    cmd: "fwconsole msm {{ }} {{ item.value }}"
    - { name: 'notification_emails', value: '{{ systems_email }}' }
    - { name: 'system_ident', value: '{{ ansible_hostname }}' }
    - { name: 'auto_module_updates', value: 'enabled' }
    - { name: 'auto_module_security_updates', value: 'enabled' }
    - { name: 'unsigned_module_emails', value: 'enabled' }
    - { name: 'update_every', value: 'monday' }
    - { name: 'update_period', value: '4to8' }

This gets me past the initial wizard (first) page So I am prompted for normal user auth on loading in the browser. On initial login the second wizard page displays wanting other settings, like lan and timezone, etc. But that is not a problem.

From here on I should be able configure the ami and ari via console and then anything else can be done using the Ansible uri module as suggested by penguinpbx.

INSERT INTO ampusers (username,password_sha1,sections) VALUES (‘admin’,’$PASSWORDSHA1’,’*’);
INSERT INTO kvstore_OOBE (key,val,type,id) VALUES (‘completed’,’{“framework”:“framework”,“soundlang”:“soundlang”}’,‘json-arr’,‘noid’);
UPDATE freepbx_settings set value = ‘America/Los_Angeles’ WHERE keyword =‘PHPTIMEZONE’;
UPDATE freepbx_settings set value = ‘en_US’ WHERE keyword =‘UIDEFAULTLANG’;
UPDATE soundlang_settings set value = ‘en_US’ WHERE keyword =‘language’;

1 Like

…snipped a little here…

    cmd: "fwconsole msm {{ }} {{ item.value }}"

I prefer the command keyword you used in earlier example vs shell keyword. Mostly command just does less than shell. But both support creates parameter, which is handy for error checking.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.