Add Ansible template
This commit is contained in:
parent
1115e86296
commit
fa1a1138d6
22 changed files with 699 additions and 3 deletions
140
roles/asterisk/tasks/main.yml
Normal file
140
roles/asterisk/tasks/main.yml
Normal file
|
@ -0,0 +1,140 @@
|
|||
- name: Check if Asterisk is already installed
|
||||
ansible.builtin.stat:
|
||||
path: /usr/sbin/asterisk
|
||||
register: asterisk_installed
|
||||
|
||||
- name: Set external signaling address
|
||||
ansible.builtin.set_fact:
|
||||
external_signaling_address: "{{ hostvars[groups['asterisk'][0]].ansible_host }}"
|
||||
when: external_signaling_address is not defined or external_signaling_address == ""
|
||||
|
||||
- name: Install build dependencies for Asterisk
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- build-essential
|
||||
- libasound2-dev
|
||||
- libedit-dev
|
||||
- libjansson-dev
|
||||
- libncurses5-dev
|
||||
- libsqlite3-dev
|
||||
- libssl-dev
|
||||
- libxml2-dev
|
||||
- uuid-dev
|
||||
- wget
|
||||
state: present
|
||||
update_cache: true
|
||||
|
||||
- name: Create a directory for PJSIP source
|
||||
ansible.builtin.file:
|
||||
path: /usr/local/src/pjsip
|
||||
state: directory
|
||||
mode: '0755'
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Download PJSIP source
|
||||
ansible.builtin.get_url:
|
||||
url: https://github.com/pjsip/pjproject/archive/refs/tags/2.14.tar.gz
|
||||
dest: /usr/local/src/pjsip/pjproject-2.14.tar.gz
|
||||
mode: '0644'
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Extract PJSIP source
|
||||
ansible.builtin.unarchive:
|
||||
src: /usr/local/src/pjsip/pjproject-2.14.tar.gz
|
||||
dest: /usr/local/src/pjsip/
|
||||
remote_src: yes
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Build and install PJSIP
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --prefix=/usr --libdir=/usr/lib
|
||||
make -j$(nproc)
|
||||
make install
|
||||
chdir: /usr/local/src/pjsip/pjproject-2.14
|
||||
args:
|
||||
creates: /usr/lib/libpj.so
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Download Asterisk source
|
||||
ansible.builtin.get_url:
|
||||
url: "https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-{{ asterisk_version }}.tar.gz"
|
||||
dest: "/usr/local/src/asterisk-{{ asterisk_version }}.tar.gz"
|
||||
mode: '0644'
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Extract Asterisk source
|
||||
ansible.builtin.unarchive:
|
||||
src: "/usr/local/src/asterisk-{{ asterisk_version }}.tar.gz"
|
||||
dest: /usr/local/src/
|
||||
remote_src: true
|
||||
creates: "/usr/local/src/asterisk-{{ asterisk_version }}"
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Configure Asterisk
|
||||
ansible.builtin.command:
|
||||
cmd: ./configure
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Enable PJSIP modules
|
||||
ansible.builtin.command:
|
||||
cmd: make menuselect.makeopts
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Compile Asterisk
|
||||
ansible.builtin.command:
|
||||
cmd: make
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Install Asterisk
|
||||
ansible.builtin.command:
|
||||
cmd: make install
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
when: not asterisk_installed.stat.exists
|
||||
|
||||
- name: Verify that PJSIP modules are installed
|
||||
ansible.builtin.stat:
|
||||
path: /usr/lib/asterisk/modules/chan_pjsip.so
|
||||
register: pjsip_module
|
||||
|
||||
- name: Fail if PJSIP modules are missing
|
||||
ansible.builtin.fail:
|
||||
msg: "PJSIP module not found! Check if libpjsip-dev was installed before building."
|
||||
when: not pjsip_module.stat.exists
|
||||
|
||||
- name: Install Asterisk samples
|
||||
ansible.builtin.command:
|
||||
cmd: make samples
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
|
||||
- name: Install Asterisk startup scripts
|
||||
ansible.builtin.command:
|
||||
cmd: make config
|
||||
chdir: "{{ asterisk_src_dir }}"
|
||||
|
||||
- name: Enable and start the Asterisk service
|
||||
ansible.builtin.service:
|
||||
name: asterisk
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: Deploy PJSIP configuration
|
||||
ansible.builtin.template:
|
||||
src: pjsip.conf.j2
|
||||
dest: "{{ asterisk_config_dir }}/pjsip.conf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: Reload Asterisk
|
||||
|
||||
- name: Deploy extensions configuration
|
||||
ansible.builtin.template:
|
||||
src: extensions.conf.j2
|
||||
dest: "{{ asterisk_config_dir }}/extensions.conf"
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: Reload Asterisk
|
Loading…
Add table
Add a link
Reference in a new issue