From 3d912670204bf184c363fc14b4b3f181c6762930 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sat, 30 Nov 2024 12:51:55 +0100 Subject: [PATCH] freepbx: Cleanup and only use flask based application --- roles/freepbx/defaults/main.yml | 11 +-- roles/freepbx/handlers/main.yml | 4 +- roles/freepbx/tasks/main.yml | 7 +- roles/freepbx/tasks/yealink_phonebook.yml | 74 ------------------- roles/freepbx/tasks/yealink_utilities.yml | 53 +++++++++++++ roles/freepbx/tasks/yealink_xml_browser.yml | 32 -------- ...ervice.j2 => yealink-utilities.service.j2} | 6 +- 7 files changed, 62 insertions(+), 125 deletions(-) delete mode 100644 roles/freepbx/tasks/yealink_phonebook.yml create mode 100644 roles/freepbx/tasks/yealink_utilities.yml delete mode 100644 roles/freepbx/tasks/yealink_xml_browser.yml rename roles/freepbx/templates/{yealink-xml-browser.service.j2 => yealink-utilities.service.j2} (59%) diff --git a/roles/freepbx/defaults/main.yml b/roles/freepbx/defaults/main.yml index 1b92020..bb135ce 100644 --- a/roles/freepbx/defaults/main.yml +++ b/roles/freepbx/defaults/main.yml @@ -6,14 +6,7 @@ asterisk_user: asterisk asterisk_group: asterisk repo_provisioning: gogs@git.binary-kitchen.de:noby/voip-yealink-provisioning.git -repo_phonebook: gogs@git.binary-kitchen.de:noby/voip-yealink-phonebook.git -repo_xml_browser: gogs@git.binary-kitchen.de:noby/voip-yealink-xml-browser.git +repo_utilities: gogs@git.binary-kitchen.de:noby/voip-yealink-xml-browser.git path_yealink_provisioning: /tftpboot/yealink -path_yealink_phonebook: /var/www/html/yealink_phonebook -path_yealink_xml_browser: /opt/yealink_xml_browser - -composer_path: "{{ path_yealink_phonebook }}/composer" -composer_keep_updated: false -composer_version: '' -composer_version_branch: '--2' +path_yealink_utilities: /opt/yealink_utilities diff --git a/roles/freepbx/handlers/main.yml b/roles/freepbx/handlers/main.yml index ff121ab..4b8029b 100644 --- a/roles/freepbx/handlers/main.yml +++ b/roles/freepbx/handlers/main.yml @@ -4,7 +4,7 @@ ansible.builtin.systemd: daemon_reload: true -- name: Restart yealink-xml-browser +- name: Restart yealink-utilities ansible.builtin.service: - name: yealink-xml-browser + name: yealink-utilities state: restarted diff --git a/roles/freepbx/tasks/main.yml b/roles/freepbx/tasks/main.yml index 75473f6..c1a0658 100644 --- a/roles/freepbx/tasks/main.yml +++ b/roles/freepbx/tasks/main.yml @@ -11,8 +11,5 @@ - name: Include provisioning tasks ansible.builtin.include_tasks: yealink_provisioning.yml -- name: Include phonebook tasks - ansible.builtin.include_tasks: yealink_phonebook.yml - -- name: Include XML-Browser tasks - ansible.builtin.include_tasks: yealink_xml_browser.yml +- name: Include XML-Utilities tasks + ansible.builtin.include_tasks: yealink_utilities.yml diff --git a/roles/freepbx/tasks/yealink_phonebook.yml b/roles/freepbx/tasks/yealink_phonebook.yml deleted file mode 100644 index c7e95f4..0000000 --- a/roles/freepbx/tasks/yealink_phonebook.yml +++ /dev/null @@ -1,74 +0,0 @@ ---- - -- name: Check if requested version parameters are valid - fail: - msg: You cannot request a specific version AND keep the composer up to date. - Set either composer_version or composer_keep_updated, but not both. - when: composer_version != '' and composer_keep_updated - -- name: Set php_executable variable to a default if not defined. - ansible.builtin.set_fact: - php_executable: php - when: php_executable is not defined - -- name: Safe Directory - command: git config --global --add safe.directory {{ path_yealink_phonebook }} - check_mode: no - -- name: Clone Phonebook generation script - ansible.builtin.git: # noqa: latest - repo: "{{ repo_phonebook }}" - dest: "{{ path_yealink_phonebook }}" - force: true - accept_hostkey: true - key_file: "{{ deploy_key_file }}" - -- name: Change directory owner - ansible.builtin.file: - path: "{{ path_yealink_phonebook }}" - recurse: yes - owner: "{{ asterisk_user }}" - group: "{{ asterisk_group }}" - -- name: Check if Composer is installed. - ansible.builtin.stat: - path: "{{ composer_path }}" - register: composer_bin - -- name: Get Composer installer signature. - ansible.builtin.uri: - url: https://composer.github.io/installer.sig - return_content: true - check_mode: false - register: composer_installer_signature - when: not composer_bin.stat.exists - -- name: Download Composer installer. - ansible.builtin.get_url: - url: https://getcomposer.org/installer - dest: /tmp/composer-installer.php - mode: "0755" - checksum: "sha384:{{ composer_installer_signature.content }}" - when: not composer_bin.stat.exists - -- name: Run Composer installer. - ansible.builtin.command: > - {{ php_executable }} composer-installer.php {% if composer_version_branch %} {{ composer_version_branch }}{% elif composer_version %} --version={{ composer_version }}{% endif %} - chdir=/tmp - when: not composer_bin.stat.exists - become: true - become_user: asterisk - -- name: Move Composer into globally-accessible location. - ansible.builtin.command: > - mv /tmp/composer.phar {{ composer_path }} - creates={{ composer_path }} - when: not composer_bin.stat.exists - -- name: Install dependencies - community.general.composer: - command: update - composer_executable: "{{ composer_path }}" - working_dir: "{{ path_yealink_phonebook }}" - become: true - become_user: asterisk diff --git a/roles/freepbx/tasks/yealink_utilities.yml b/roles/freepbx/tasks/yealink_utilities.yml new file mode 100644 index 0000000..f717f69 --- /dev/null +++ b/roles/freepbx/tasks/yealink_utilities.yml @@ -0,0 +1,53 @@ +--- + +- name: Install dependencies + ansible.builtin.package: + name: "python3-venv" + state: present + +- name: Check if .gitignore contains "{{ path_yealink_utilities }}" + ansible.builtin.command: grep "directory = {{ path_yealink_utilities }}" /root/.gitconfig + register: gitignore_check + ignore_errors: true + +- name: "Patch /root/.gitconfig" + ansible.builtin.command: |- + git config --global --add safe.directory {{ path_yealink_utilities }} + when: gitignore_check.rc != 0 + +- name: Clone Yealink Utilities + ansible.builtin.git: # noqa: latest + repo: "{{ repo_utilities }}" + dest: "{{ path_yealink_utilities }}" + force: true + accept_hostkey: true + key_file: "{{ deploy_key_file }}" + +- name: Ensure directory permissions + ansible.builtin.file: + path: "{{ path_yealink_utilities }}" + state: directory + recurse: true + owner: "{{ asterisk_user }}" + group: "{{ asterisk_group }}" + +- name: Install specified python requirements in indicated (virtualenv) + ansible.builtin.pip: + requirements: "{{ path_yealink_utilities }}/requirements.txt" + virtualenv: "{{ path_yealink_utilities }}/.venv" + virtualenv_command: 'python3 -m venv' + +- name: Install systemd unit + ansible.builtin.template: + src: yealink-utilities.service.j2 + dest: /etc/systemd/system/yealink-utilities.service + mode: "0644" + notify: + - Reload systemd + - Restart yealink-utilities + +- name: Enable yealink-utilities + ansible.builtin.service: + name: yealink-utilities + state: started + enabled: true diff --git a/roles/freepbx/tasks/yealink_xml_browser.yml b/roles/freepbx/tasks/yealink_xml_browser.yml deleted file mode 100644 index cb36089..0000000 --- a/roles/freepbx/tasks/yealink_xml_browser.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - -- name: Install dependencies - ansible.builtin.package: - name: "python3-venv" - state: present - -- name: Clone Yealink XML-Browser - ansible.builtin.git: # noqa: latest - repo: "{{ repo_xml_browser }}" - dest: "{{ path_yealink_xml_browser }}" - force: true - accept_hostkey: true - key_file: "{{ deploy_key_file }}" - -- name: Install specified python requirements in indicated (virtualenv) - ansible.builtin.pip: - requirements: "{{ path_yealink_xml_browser }}/requirements.txt" - virtualenv: "{{ path_yealink_xml_browser }}/.venv" - virtualenv_command: 'python3 -m venv' - -- name: Install systemd unit - template: src=yealink-xml-browser.service.j2 dest=/lib/systemd/system/yealink-xml-browser.service - notify: - - Reload systemd - - Restart yealink-xml-browser - -- name: Enable yealink-xml-browser - ansible.builtin.service: - name: yealink-xml-browser - state: started - enabled: yes diff --git a/roles/freepbx/templates/yealink-xml-browser.service.j2 b/roles/freepbx/templates/yealink-utilities.service.j2 similarity index 59% rename from roles/freepbx/templates/yealink-xml-browser.service.j2 rename to roles/freepbx/templates/yealink-utilities.service.j2 index acbd695..f6fbac6 100644 --- a/roles/freepbx/templates/yealink-xml-browser.service.j2 +++ b/roles/freepbx/templates/yealink-utilities.service.j2 @@ -8,9 +8,9 @@ RestartSec=2s Type=simple User={{ asterisk_user }} Group={{ asterisk_group }} -Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:{{ path_yealink_xml_browser }}/.venv/bin" -WorkingDirectory={{ path_yealink_xml_browser }} -ExecStart={{ path_yealink_xml_browser }}/.venv/bin/python3 {{ path_yealink_xml_browser }}/main.py +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:{{ path_yealink_utilities }}/.venv/bin" +WorkingDirectory={{ path_yealink_utilities }} +ExecStart={{ path_yealink_utilities }}/.venv/bin/python3 {{ path_yealink_utilities }}/run.py Restart=always [Install]