diff --git a/data/ansible/roles/cgrates/defaults/main.yaml b/data/ansible/roles/cgrates/defaults/main.yaml index 36db54999..a83fd63e6 100644 --- a/data/ansible/roles/cgrates/defaults/main.yaml +++ b/data/ansible/roles/cgrates/defaults/main.yaml @@ -1,9 +1,14 @@ --- -golang_gopath: "/home/{{ ansible_user }}/go" +golang_gopath: '/home/{{ ansible_user }}/go' clone_repository: true -cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates" +cgrates_dir: '{{ golang_gopath }}/src/github.com/cgrates/cgrates' golang_install_dir: /usr/local/go -git_version: "v0.10" +git_version: v0.10 +cgrates_migrator_cfg_path: /usr/share/cgrates/conf/samples/tutmysql # leave empty to do nothing +cgrates_dbs: + - mysql + - postgres + - mongo # CGRateS dependencies cgrates_dependencies: diff --git a/data/ansible/roles/cgrates/tasks/main.yaml b/data/ansible/roles/cgrates/tasks/main.yaml index 6f3d4b1ef..5e7bf680e 100644 --- a/data/ansible/roles/cgrates/tasks/main.yaml +++ b/data/ansible/roles/cgrates/tasks/main.yaml @@ -1,61 +1,69 @@ --- - name: Install CGRateS dependencies - become: yes + become: true ansible.builtin.package: - name: "{{ cgrates_dependencies }}" + name: '{{ cgrates_dependencies }}' state: present update_cache: yes - name: Create cgrates directory ansible.builtin.file: state: directory - mode: "u=rwx,go=rx" - owner: "{{ ansible_user }}" - dest: "{{ cgrates_dir }}" + mode: u=rwx,go=rx + owner: '{{ ansible_user }}' + dest: '{{ cgrates_dir }}' when: clone_repository | bool - name: Git clone cgrates ansible.builtin.git: repo: https://github.com/cgrates/cgrates.git - dest: "{{ cgrates_dir }}" + dest: '{{ cgrates_dir }}' update: yes force: yes - version: "{{ git_version }}" + version: '{{ git_version }}' when: clone_repository | bool - name: Build cgrates ansible.builtin.shell: cmd: bash -lc "sh {{ cgrates_dir }}/build.sh" args: - chdir: "{{ cgrates_dir }}" - become_user: "{{ ansible_user }}" + chdir: '{{ cgrates_dir }}' + become_user: '{{ ansible_user }}' - name: Create symbolic links ansible.builtin.file: - src: "{{ item.src }}" - dest: "{{ item.dest }}" + src: '{{ item.src }}' + dest: '{{ item.dest }}' state: link - become: yes + become: true loop: - - { src: "{{ cgrates_dir }}/data", dest: "/usr/share/cgrates" } - - { src: "{{ golang_gopath }}/bin/cgr-engine", dest: "/usr/bin/cgr-engine" } - - { src: "{{ golang_gopath }}/bin/cgr-loader", dest: "/usr/bin/cgr-loader" } - - { src: "{{ golang_gopath }}/bin/cgr-migrator", dest: "/usr/bin/cgr-migrator" } - - { src: "{{ golang_gopath }}/bin/cgr-console", dest: "/usr/bin/cgr-console" } - - { src: "{{ golang_gopath }}/bin/cgr-tester", dest: "/usr/bin/cgr-tester" } + - { src: '{{ cgrates_dir }}/data', dest: '/usr/share/cgrates' } + - { src: '{{ golang_gopath }}/bin/cgr-engine', dest: '/usr/bin/cgr-engine' } + - { src: '{{ golang_gopath }}/bin/cgr-loader', dest: '/usr/bin/cgr-loader' } + - { + src: '{{ golang_gopath }}/bin/cgr-migrator', + dest: '/usr/bin/cgr-migrator', + } + - { + src: '{{ golang_gopath }}/bin/cgr-console', + dest: '/usr/bin/cgr-console', + } + - { src: '{{ golang_gopath }}/bin/cgr-tester', dest: '/usr/bin/cgr-tester' } - name: Run post install scripts + become: true ansible.builtin.command: - cmd: "{{ item.cmd }}" - chdir: "{{ cgrates_dir }}/data/storage/{{ item.db }}" - become: yes + cmd: '{{ item.cmd }}' + chdir: '{{ cgrates_dir }}/data/storage/{{ item.db }}' + when: item.db in cgrates_dbs loop: - - { db: "mysql", cmd: "sh setup_ers_db.sh root CGRateS.org localhost" } - - { db: "mysql", cmd: "sh setup_cgr_db.sh root CGRateS.org localhost" } - - { db: "postgres", cmd: "sh setup_cgr_db.sh" } - - { db: "postgres", cmd: "sh create_ers_db.sh" } - - { db: "mongo", cmd: "sh setup_cgr_db.sh" } + - { db: 'mysql', cmd: 'sh setup_ers_db.sh root CGRateS.org localhost' } + - { db: 'mysql', cmd: 'sh setup_cgr_db.sh root CGRateS.org localhost' } + - { db: 'postgres', cmd: 'sh create_db_with_users.sh' } + - { db: 'postgres', cmd: 'sh create_ers_db.sh' } + - { db: 'mongo', cmd: 'sh setup_cgr_db.sh' } - name: Set versions ansible.builtin.command: - cmd: "cgr-migrator -exec=*set_versions -config_path=/usr/share/cgrates/conf/samples/tutmysql" + cmd: 'cgr-migrator -exec=*set_versions -config_path={{ cgrates_migrator_cfg_path }}' + when: cgrates_migrator_cfg_path != "" diff --git a/data/ansible/roles/go/defaults/main.yaml b/data/ansible/roles/go/defaults/main.yaml index 919764bcd..682a4bd32 100644 --- a/data/ansible/roles/go/defaults/main.yaml +++ b/data/ansible/roles/go/defaults/main.yaml @@ -1,8 +1,8 @@ --- -go_version: '1.22.3' +go_version: 1.22.3 go_platform: linux go_arch: amd64 go_tarball: go{{ go_version }}.{{ go_platform }}-{{ go_arch }}.tar.gz go_download_url: https://dl.google.com/go/{{ go_tarball }} -go_checksum: '8920ea521bad8f6b7bc377b4824982e011c19af27df88a815e3586ea895f1b36' +go_checksum: 8920ea521bad8f6b7bc377b4824982e011c19af27df88a815e3586ea895f1b36 install_go: true diff --git a/data/ansible/roles/go/tasks/main.yaml b/data/ansible/roles/go/tasks/main.yaml index b35d99105..0e50e1835 100644 --- a/data/ansible/roles/go/tasks/main.yaml +++ b/data/ansible/roles/go/tasks/main.yaml @@ -6,7 +6,7 @@ changed_when: false - name: Remove current installation. - become: yes + become: true file: state: absent path: /usr/local/go @@ -16,17 +16,17 @@ - go_version not in go_version_result.stdout - name: Download Go. - become: yes + become: true get_url: - url: "{{ go_download_url }}" + url: '{{ go_download_url }}' dest: /usr/local/src/{{ go_tarball }} - checksum: "sha256:{{ go_checksum }}" + checksum: 'sha256:{{ go_checksum }}' when: - install_go | bool - (go_version_result is failed or go_version not in go_version_result.stdout) - name: Extract Go. - become: yes + become: true unarchive: src: /usr/local/src/{{ go_tarball }} dest: /usr/local @@ -36,7 +36,7 @@ - (go_version_result is failed or go_version not in go_version_result.stdout) - name: Add Go to to system-wide $PATH. - become: yes + become: true copy: dest: /etc/profile.d/go-path.sh content: |- diff --git a/data/ansible/roles/mongodb/tasks/main.yaml b/data/ansible/roles/mongodb/tasks/main.yaml index ae9c20f8a..c22ab1f42 100644 --- a/data/ansible/roles/mongodb/tasks/main.yaml +++ b/data/ansible/roles/mongodb/tasks/main.yaml @@ -1,6 +1,6 @@ --- - name: Determine the version of MongoDB - become: yes + become: true command: mongod --version register: mongodb_version_check changed_when: false @@ -12,40 +12,48 @@ - name: Set fact for MongoDB installation required set_fact: - mongodb_installation_required: "{{ mongodb_current_version != mongodb_version }}" + mongodb_installation_required: '{{ mongodb_current_version != mongodb_version }}' - block: - name: Install dependencies - become: yes + become: true apt: - name: "{{ mongodb_dependencies }}" + name: '{{ mongodb_dependencies }}' state: present update_cache: yes - name: Import the MongoDB public GPG Key - become: yes + become: true apt_key: - url: "https://pgp.mongodb.com/server-{{ mongodb_version }}.asc" - keyring: "/usr/share/keyrings/mongodb-server-{{ mongodb_version }}.gpg" + url: 'https://pgp.mongodb.com/server-{{ mongodb_version }}.asc' + keyring: '/usr/share/keyrings/mongodb-server-{{ mongodb_version }}.gpg' - - name: Add MongoDB repository - become: yes + - name: Add MongoDB repository for Debian + become: true apt_repository: - repo: "deb [ signed-by=/usr/share/keyrings/mongodb-server-{{ mongodb_version }}.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/{{ mongodb_version }} main" - filename: "{{ mongodb_package_name }}-{{ mongodb_version }}" + repo: 'deb [ signed-by=/usr/share/keyrings/mongodb-server-{{ mongodb_version }}.gpg ] http://repo.mongodb.org/apt/debian {{ ansible_distribution_release }}/mongodb-org/{{ mongodb_version }} main' + filename: '{{ mongodb_package_name }}-{{ mongodb_version }}' + when: ansible_distribution == 'Debian' + + - name: Add MongoDB repository for Ubuntu + become: true + apt_repository: + repo: 'deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-{{ mongodb_version }}.gpg ] https://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/{{ mongodb_version }} multiverse' + filename: '{{ mongodb_package_name }}-{{ mongodb_version }}' + when: ansible_distribution == 'Ubuntu' - name: Install MongoDB packages - become: yes + become: true apt: - name: "{{ mongodb_package_name }}" + name: '{{ mongodb_package_name }}' state: present update_cache: yes - name: Start and enable MongoDB service - become: yes + become: true ansible.builtin.systemd: - name: "{{ mongodb_service_name }}" - state: "{{ mongodb_service_state }}" - enabled: "{{ mongodb_service_enabled }}" + name: '{{ mongodb_service_name }}' + state: '{{ mongodb_service_state }}' + enabled: '{{ mongodb_service_enabled }}' when: mongodb_installation_required diff --git a/data/ansible/roles/opensips/defaults/main.yaml b/data/ansible/roles/opensips/defaults/main.yaml new file mode 100644 index 000000000..7af35b952 --- /dev/null +++ b/data/ansible/roles/opensips/defaults/main.yaml @@ -0,0 +1,18 @@ +--- +opensips_version: 3.5 +opensips_release_type: nightly # releases or nightly +opensips_service_enabled: false +opensips_service_state: stopped +opensips_cfg_path: '' # path to a custom cfg file to replace the default one (do nothing if empty) +opensips_dict_path: '' # add dict file found at specified path to /etc/opensips +opensips_modules: + - opensips-cgrates-module + # - opensips-auth-modules + # - opensips-diameter-module + # - opensips-json-module + # - opensips-mysql-module +opensips_cfg_replacements: [] +# - { before: 'regex_pattern1', after: 'replacement1' } +# - { before: 'regex_pattern2', after: 'replacement2' } +opensips_dependencies: [] +# - mariadb-server diff --git a/data/ansible/roles/opensips/tasks/main.yaml b/data/ansible/roles/opensips/tasks/main.yaml new file mode 100644 index 000000000..328d1d790 --- /dev/null +++ b/data/ansible/roles/opensips/tasks/main.yaml @@ -0,0 +1,89 @@ +--- +- name: Install dependencies + become: true + apt: + name: '{{ opensips_dependencies }}' + state: present + update_cache: yes + +- name: Import OpenSIPS GPG key + become: true + ansible.builtin.get_url: + url: https://apt.opensips.org/opensips-org.gpg + dest: /usr/share/keyrings/opensips-org.gpg + mode: '0644' + +- name: Configure OpenSIPS APT repository + become: true + ansible.builtin.copy: + content: "deb [signed-by=/usr/share/keyrings/opensips-org.gpg] https://apt.opensips.org {{ ansible_distribution_release }} {{ opensips_version }}-{{ opensips_release_type }}\n" + dest: /etc/apt/sources.list.d/opensips.list + owner: root + group: root + mode: '0644' + +- name: Configure OpenSIPS CLI APT repository + become: true + ansible.builtin.copy: + content: "deb [signed-by=/usr/share/keyrings/opensips-org.gpg] https://apt.opensips.org {{ ansible_distribution_release }} cli-nightly\n" + dest: /etc/apt/sources.list.d/opensips-cli.list + owner: root + group: root + mode: '0644' + +- name: Update APT cache + become: true + ansible.builtin.apt: + update_cache: yes + +- name: Install OpenSIPS and OpenSIPS CLI + become: true + ansible.builtin.apt: + name: + - opensips + - opensips-cli + state: present + +- name: Install additional OpenSIPS modules + become: true + ansible.builtin.apt: + name: '{{ opensips_modules }}' + state: present + +- name: Replace default OpenSIPS configuration if custom path provided + become: true + ansible.builtin.copy: + src: '{{ opensips_cfg_path }}' + dest: /etc/opensips/opensips.cfg + owner: root + group: root + remote_src: yes + mode: '0644' + when: opensips_cfg_path != "" + +- name: Copy OpenSIPS dictionary file from specified path (if any) + become: true + ansible.builtin.copy: + src: '{{ opensips_dict_path }}' + dest: '/etc/opensips/dictionary.opensips' + owner: root + group: root + remote_src: yes + mode: '0644' + when: opensips_dict_path != "" + +- name: Replace lines in OpenSIPS config with specified rules + become: true + ansible.builtin.lineinfile: + path: /etc/opensips/opensips.cfg + regexp: '{{ item.before }}' + line: '{{ item.after }}' + backrefs: true + loop: '{{ opensips_cfg_replacements }}' + +- name: Ensure OpenSIPS service is in the desired state + become: true + ansible.builtin.systemd: + name: opensips + enabled: '{{ opensips_service_enabled }}' + state: '{{ opensips_service_state }}' diff --git a/data/ansible/roles/pjsua/defaults/main.yaml b/data/ansible/roles/pjsua/defaults/main.yaml index 273ed18fe..fcb9d8c80 100644 --- a/data/ansible/roles/pjsua/defaults/main.yaml +++ b/data/ansible/roles/pjsua/defaults/main.yaml @@ -1,10 +1,11 @@ --- -pjsua_version: "2.9" -pjsua_url: "https://github.com/pjsip/pjproject/archive/refs/tags/{{ pjsua_version }}.tar.gz" -tmp_dir: "/tmp" - -# PJSUA dependencies +pjsua_version: 2.9 +pjsua_url: 'https://github.com/pjsip/pjproject/archive/refs/tags/{{ pjsua_version }}.tar.gz' +pjsua_tmp_install_dir: /tmp +pjsua_post_install_cleanup: true +pjsua_bin_path: /usr/local/bin pjsua_dependencies: - libasound2-dev - libssl-dev - - build-essential \ No newline at end of file + - build-essential +pjsua_helper_scripts: false diff --git a/data/ansible/roles/pjsua/files/pjsua_call b/data/ansible/roles/pjsua/files/pjsua_call new file mode 100755 index 000000000..a44851c36 --- /dev/null +++ b/data/ansible/roles/pjsua/files/pjsua_call @@ -0,0 +1,107 @@ +#!/bin/bash + +# Default values +HOST=127.0.0.1 +LOCAL_PORT=$(comm -23 <(seq 32768 60999 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1) +REGISTRAR_PORT=5060 +PASSWORD="CGRateS.org" +VERBOSE=false +DRYRUN=false + +# Parse command line options +OPTS=$(getopt -o f:t:d:p:r:P:vDh --long from:,to:,dur:,port:,registrar:,passwd:,verbose,dryrun,help -n "$(basename "$0")" -- "$@") +if [ $? -ne 0 ]; then + echo "Failed to parse options." >&2 + exit 1 +fi + +eval set -- "$OPTS" + +while true; do + case "$1" in + -f|--from) + from="$2" + shift 2 + ;; + -t|--to) + to="$2" + shift 2 + ;; + -d|--dur) + duration="$2" + shift 2 + ;; + -H|--host) + HOST=$2 + shift 2 + ;; + -p|--port) + LOCAL_PORT="$2" + shift 2 + ;; + -r|--registrar) + REGISTRAR_PORT="$2" + shift 2 + ;; + -P|--passwd) + PASSWORD="$2" + shift 2 + ;; + -v|--verbose) + VERBOSE=true + shift + ;; + -D|--dryrun) + DRYRUN=true + VERBOSE=true + shift + ;; + -h|--help) + echo "Usage: $(basename "$0") [OPTIONS]" + echo + echo "Options:" + echo "-f, --from ID of calling party" + echo "-t, --to ID of called party" + echo "-d, --dur Duration of the call" + echo "-H, --host Set the host of accounts" + echo " Defaults to 127.0.0.1" + echo "-p, --port Set the call port" + echo " Defaults to a random one" + echo "-r, --registrar Set the registrar port" + echo " Default: ${REGISTRAR_PORT}" + echo "-P, --passwd Input account password" + echo "-v, --verbose Print command before executing" + echo "-D, --dryrun Print command without executing" + echo "-h, --help Display this usage information" + + shift + exit 1 + ;; + --) + shift + break + ;; + *) + echo "Internal error!" + exit 1 + ;; + esac +done + +# Check for missing options +if [ -z "$from" ] || [ -z "$to" ] || [ -z "$duration" ]; then + echo "Mandatory options are missing: -f/--from, -t/--to, -d/--dur" + exit 1 +fi + +# Build the command +cmd="pjsua --null-audio --app-log-level=0 --local-port=${LOCAL_PORT} --duration=${duration} --outbound=sip:${HOST}:${REGISTRAR_PORT}" +cmd+=" --id=sip:${from}@${HOST} --username=${from} --password=${PASSWORD} --realm=* sip:${to}@${HOST}" + +# Execute the command +if [ "${VERBOSE}" = true ]; then + echo "Executing: ${cmd}" +fi +if [ "${DRYRUN}" = false ]; then + ${cmd} +fi \ No newline at end of file diff --git a/data/ansible/roles/pjsua/files/pjsua_listen b/data/ansible/roles/pjsua/files/pjsua_listen new file mode 100755 index 000000000..5065a6121 --- /dev/null +++ b/data/ansible/roles/pjsua/files/pjsua_listen @@ -0,0 +1,106 @@ +#!/bin/bash + +# Default values +HOST=127.0.0.1 +LOCAL_PORT=$(comm -23 <(seq 32768 60999 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1) +REGISTRAR_PORT=5060 +PASSWORD="CGRateS.org" +VERBOSE=false +DRYRUN=false + +# Parse command line options +OPTS=$(getopt -o a:H:p:r:P:vDh --long accounts:,host:,port:,registrar:,passwd:,verbose,dryrun,help -n "$(basename "$0")" -- "$@") +if [ $? -ne 0 ]; then + echo "Failed to parse options." >&2 + exit 1 +fi + +eval set -- "$OPTS" + +while true; do + case "$1" in + -a|--accounts) + IFS=',' read -r -a accounts <<< "$2" + shift 2 + ;; + -H|--host) + HOST=$2 + shift 2 + ;; + -p|--port) + LOCAL_PORT="$2" + shift 2 + ;; + -r|--registrar) + REGISTRAR_PORT="$2" + shift 2 + ;; + -P|--passwd) + PASSWORD="$2" + shift 2 + ;; + -v|--verbose) + VERBOSE=true + shift + ;; + -D|--dryrun) + DRYRUN=true + VERBOSE=true + shift + ;; + -h|--help) + echo "Usage: $(basename "$0") [OPTIONS]" + echo + echo "Options:" + echo "-a, --accounts List of accounts to register" + echo "-H, --host Set the host of account" + echo " Defaults to 127.0.0.1" + echo "-p, --port Set the PJSUA listener port" + echo " Defaults to a random one" + echo "-r, --registrar Set the registrar port" + echo " Default: ${REGISTRAR_PORT}" + echo "-P, --passwd Set account password" + echo "-v, --verbose Print command before executing" + echo "-D, --dryrun Print command without executing" + echo "-h, --help Display this usage information" + + shift + exit 1 + ;; + --) + shift + break + ;; + *) + echo "Internal error!" + exit 1 + ;; + esac +done + +# Check for missing accounts +if [ ${#accounts[@]} -eq 0 ]; then + echo "No accounts specified. Use -a or --accounts to specify comma-separated accounts." + exit 1 +fi + +# Start building the command +cmd="pjsua --local-port=${LOCAL_PORT} --null-audio --auto-answer=200 --max-calls=4 --app-log-level=0" + +# Add accounts +first=true +for acc in "${accounts[@]}"; do + if [ "${first}" != true ]; then + cmd+=" --next-account" + fi + first=false + cmd+=" --id=sip:${acc}@${HOST} --registrar=sip:${HOST}:${REGISTRAR_PORT} --username=${acc} --password=${PASSWORD} --realm=*" +done + +# Execute the command +if [ "${VERBOSE}" = true ]; then + echo "Executing: ${cmd}" +fi +if [ "${DRYRUN}" = false ]; then + ${cmd} +fi diff --git a/data/ansible/roles/pjsua/tasks/main.yaml b/data/ansible/roles/pjsua/tasks/main.yaml index 41c9aea7d..7ae807069 100644 --- a/data/ansible/roles/pjsua/tasks/main.yaml +++ b/data/ansible/roles/pjsua/tasks/main.yaml @@ -1,38 +1,63 @@ --- +- name: Check if PJSUA is installed and get version + ansible.builtin.shell: + cmd: pjsua --version | grep 'PJ_VERSION' | awk '{print $NF}' + register: installed_pjsua_version + ignore_errors: true + changed_when: false + - name: Install PJSUA dependencies - become: yes + become: true ansible.builtin.package: name: '{{ pjsua_dependencies }}' state: present update_cache: yes - cache_valid_time: 86400 + when: installed_pjsua_version.stdout != pjsua_version - name: Download PJSUA ansible.builtin.get_url: - url: "{{ pjsua_url }}" - dest: "{{ tmp_dir }}/{{ pjsua_version }}.tar.gz" + url: '{{ pjsua_url }}' + dest: '{{ pjsua_tmp_install_dir }}/{{ pjsua_version }}.tar.gz' + when: installed_pjsua_version.stdout != pjsua_version - name: Unzip PJSUA - become: yes + become: true ansible.builtin.unarchive: - src: "{{ tmp_dir }}/{{ pjsua_version }}.tar.gz" - dest: "{{ tmp_dir }}" + src: '{{ pjsua_tmp_install_dir }}/{{ pjsua_version }}.tar.gz' + dest: '{{ pjsua_tmp_install_dir }}' remote_src: yes + when: installed_pjsua_version.stdout != pjsua_version - name: Install PJSUA - become: yes + become: true ansible.builtin.shell: cmd: './configure CFLAGS="$CFLAGS -fPIC" && make dep && make && make install' - chdir: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}' + chdir: '{{ pjsua_tmp_install_dir }}/pjproject-{{ pjsua_version }}' + when: installed_pjsua_version.stdout != pjsua_version -- name: Copy PJSUA into /usr/bin - become: yes - ansible.builtin.command: - cmd: 'cp pjsua-x86_64-unknown-linux-gnu /usr/bin/pjsua' - chdir: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}/pjsip-apps/bin' +- name: Copy PJSUA into configured bin path + become: true + ansible.builtin.copy: + src: '{{ pjsua_tmp_install_dir }}/pjproject-{{ pjsua_version }}/pjsip-apps/bin/pjsua-x86_64-unknown-linux-gnu' + dest: '{{ pjsua_bin_path }}/pjsua' + remote_src: yes + mode: '0755' + when: installed_pjsua_version.stdout != pjsua_version - name: Cleanup temporary PJSUA files - become: yes + become: true ansible.builtin.file: - path: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}' + path: '{{ pjsua_tmp_install_dir }}/pjproject-{{ pjsua_version }}' state: absent + when: pjsua_post_install_cleanup | bool + +- name: Deploy pjsua helper scripts + become: true + ansible.builtin.copy: + src: '{{ item }}' + dest: '{{ pjsua_bin_path }}/{{ item }}' + mode: '0755' + loop: + - pjsua_call + - pjsua_listen + when: pjsua_helper_scripts | bool diff --git a/data/ansible/roles/postgresql/defaults/main.yaml b/data/ansible/roles/postgresql/defaults/main.yaml index c631e6a1a..392891f91 100644 --- a/data/ansible/roles/postgresql/defaults/main.yaml +++ b/data/ansible/roles/postgresql/defaults/main.yaml @@ -1,6 +1,6 @@ --- -postgresql_version: "postgresql" -postgresql_repo: "http://apt.postgresql.org/pub/repos/apt" -postgresql_key_url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc" -postgresql_service_state: "started" -postgresql_service_enabled: "no" +postgresql_version: postgresql +postgresql_repo: http://apt.postgresql.org/pub/repos/apt +postgresql_key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc +postgresql_service_state: started +postgresql_service_enabled: false diff --git a/data/ansible/roles/postgresql/tasks/main.yaml b/data/ansible/roles/postgresql/tasks/main.yaml index 77f6a5dd9..93c73dad0 100644 --- a/data/ansible/roles/postgresql/tasks/main.yaml +++ b/data/ansible/roles/postgresql/tasks/main.yaml @@ -1,27 +1,27 @@ --- - name: Create the PostgreSQL repository configuration - become: yes + become: true ansible.builtin.copy: - content: "deb {{ postgresql_repo }} {{ ansible_distribution_release }}-pgdg main" + content: 'deb {{ postgresql_repo }} {{ ansible_distribution_release }}-pgdg main' dest: /etc/apt/sources.list.d/pgdg.list when: not (ansible.builtin.stat.exists is defined and ansible.builtin.stat.exists) - name: Import the PostgreSQL repository signing key - become: yes + become: true ansible.builtin.apt_key: - url: "{{ postgresql_key_url }}" + url: '{{ postgresql_key_url }}' state: present - name: Update the package lists and ensure PostgreSQL is the latest version - become: yes + become: true ansible.builtin.apt: - name: "{{ postgresql_version }}" + name: '{{ postgresql_version }}' state: latest update_cache: yes - name: Manage the PostgreSQL service - become: yes + become: true ansible.builtin.systemd: name: postgresql - state: "{{ postgresql_service_state }}" - enabled: "{{ postgresql_service_enabled }}" + state: '{{ postgresql_service_state }}' + enabled: '{{ postgresql_service_enabled }}' diff --git a/data/ansible/roles/sipp/defaults/main.yaml b/data/ansible/roles/sipp/defaults/main.yaml new file mode 100644 index 000000000..79cc887bb --- /dev/null +++ b/data/ansible/roles/sipp/defaults/main.yaml @@ -0,0 +1,13 @@ +--- +sipp_clone_path: '{{ ansible_env.HOME }}' +sipp_bin_path: /usr/local/bin +sipp_cmake_flags: '' # '-DUSE_SSL=1 -DUSE_SCTP=1 -DUSE_PCAP=1 -DUSE_GSL=1' +sipp_remove_source: true +sipp_version: v3.7.2 +sipp_dependencies: + - git + - cmake + - make + - gcc + - g++ + - libncurses-dev diff --git a/data/ansible/roles/sipp/tasks/main.yaml b/data/ansible/roles/sipp/tasks/main.yaml new file mode 100644 index 000000000..76ef5ff91 --- /dev/null +++ b/data/ansible/roles/sipp/tasks/main.yaml @@ -0,0 +1,58 @@ +--- +- name: Check if SIPp is installed and get version + ansible.builtin.shell: + cmd: sipp -v | grep 'SIPp v' | awk '{print $2}' | sed 's/.$//' + register: sipp_installed_version + ignore_errors: true + changed_when: false + +# - name: Debug SIPp version +# debug: +# msg: "Installed SIPp version is '{{ sipp_installed_version.stdout }}'" + +- name: Install dependencies for building SIPp + become: true + ansible.builtin.apt: + name: '{{ sipp_dependencies }}' + state: present + when: sipp_installed_version.stdout != sipp_version and ansible_os_family == "Debian" + +- name: Clone SIPp repository + ansible.builtin.git: + repo: https://github.com/SIPp/sipp.git + dest: '{{ sipp_clone_path }}/sipp' + version: '{{ sipp_version }}' + when: sipp_installed_version.stdout != sipp_version + +- name: Build SIPp + block: + - name: Create build directory + ansible.builtin.file: + path: '{{ sipp_clone_path }}/sipp/build' + state: directory + + - name: Run CMake + ansible.builtin.command: + cmd: cmake .. {{ sipp_cmake_flags }} + chdir: '{{ sipp_clone_path }}/sipp/build' + + - name: Run Make + ansible.builtin.command: + cmd: make + chdir: '{{ sipp_clone_path }}/sipp/build' + when: sipp_installed_version.stdout != sipp_version + +- name: Move SIPp binary to the installation path + become: true + ansible.builtin.copy: + src: '{{ sipp_clone_path }}/sipp/build/sipp' + dest: '{{ sipp_bin_path }}' + remote_src: yes + mode: '0755' + when: sipp_installed_version.stdout != sipp_version + +- name: Remove SIPp source directory + ansible.builtin.file: + path: '{{ sipp_clone_path }}/sipp' + state: absent + when: sipp_installed_version.stdout != sipp_version and sipp_remove_source