๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/asterisk/tasks/main.yml

195 lines
5.0 KiB

2 years ago
- name: set asterisk_cfg
set_fact:
asterisk_cfg: "{{ asterisk_default_config | d({}) | combine(asterisk_config | d({}), recursive=true) }}"
- name: install dependencies
include_tasks: tasks/install_packages.yml
vars:
package:
- asterisk
- asterisk-pgsql
- asterisk-openrc
- asterisk-opus
- asterisk-srtp
- tar
- vorbis-tools
- name: create user and group
include_tasks: tasks/create_user.yml
vars:
user:
name: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
dir: "{{ asterisk_dir }}"
- name: ensure asterisk directories exist
file:
path: "{{ item }}"
state: directory
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
loop:
- "{{ asterisk_dir }}"
- "{{ asterisk_conf_dir }}"
- "{{ asterisk_tls_dir }}"
- "{{ asterisk_data_dir }}"
- "{{ asterisk_data_dir }}/moh"
- "{{ asterisk_data_dir }}/sounds"
- "{{ asterisk_data_dir }}/sounds/{{ asterisk_language }}"
- "{{ asterisk_data_dir }}/sounds/{{ asterisk_language }}/custom"
- "{{ asterisk_recordings_dir }}"
- name: template custom asterisk configs
template:
src: "{{ item }}.j2"
dest: "{{ asterisk_conf_dir }}/{{ item }}.conf"
force: yes
mode: 0400
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
lstrip_blocks: yes
notify: restart asterisk
loop:
- custom_pjsip
- custom_queues
- ext_ivr
- ext_utils
- extensions
- name: template asterisk configs
template:
src: "{{ 'config' if item is string else (item.config | d('config')) }}.j2"
dest: "{{ asterisk_conf_dir }}/{{ item if item is string else (item.dest | d(item.config) | d(item.name)) }}.conf"
force: yes
mode: 0400
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
lstrip_blocks: yes
notify: restart asterisk
loop:
- acl
- asterisk
- ccss
- cdr
- cdr_pgsql
- cli_aliases
- cli_permissions
- codecs
- confbridge
- features
- followme
- indications
- logger
- manager
- musiconhold
- pjproject
- pjsip
- pjsip_notify
- queues
- rtp
- modules
- queuerules
- cel
- udptl
- name: edit service config
lineinfile:
path: /etc/conf.d/asterisk
regexp: "^{{ item.name | upper }}="
line: "{{ item.name | upper }}=\"{{ item.value }}\""
when: item.when | d(true)
notify: restart asterisk
loop:
- name: asterisk_opts
value: "-C {{ (asterisk_conf_dir ~ '/asterisk.conf') | quote }}"
when: "{{ asterisk_conf_dir != '/etc/asterisk' }}"
- name: asterisk_user
value: "{{ asterisk_user }}"
- name: asterisk_nice
value: "{{ asterisk_niceness | d(None) }}"
when: "{{ asterisk_niceness is defined }}"
- name: download asterisk sound pack
get_url:
url: "https://downloads.asterisk.org/pub/telephony/sounds/asterisk-core-sounds-{{ asterisk_language }}-{{ item }}-current.tar.gz"
dest: "{{ asterisk_data_dir }}/{{ asterisk_language }}-{{ item }}.tar.gz"
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
register: result
loop:
- sln16
- wav
- name: extract sound pack
unarchive:
src: "{{ item }}"
dest: "{{ asterisk_data_dir }}/sounds/{{ asterisk_language }}"
remote_src: yes
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
loop: "{{ result.results | d([]) | selectattr('dest', 'defined') | selectattr('changed', 'defined') | selectattr('changed', 'equalto', true) | map(attribute='dest') | list }}"
- name: deploy RSA cert for SIP TLS
include_role:
name: certs
vars:
certs:
id: ast-tls
cert: "{{ asterisk_tls_dir }}/asterisk.crt"
key: "{{ asterisk_tls_dir }}/asterisk.key"
chain: "{{ asterisk_tls_dir }}/chain.crt"
owner: "{{ asterisk_user }}"
group: "{{ asterisk_group }}"
post_hook: service asterisk restart
notify: restart asterisk
- name: install and configure cdr
include_role:
name: cdr
vars:
cdr_group: "{{ asterisk_group }}"
cdr_config:
db_host: "{{ asterisk_cfg.cdr_pgsql.global.hostname }}"
db_user: "{{ asterisk_cfg.cdr_pgsql.global.user }}"
db_pass: "{{ asterisk_cfg.cdr_pgsql.global.password }}"
db_database: "{{ asterisk_cfg.cdr_pgsql.global.dbname }}"
db_table: "{{ asterisk_cfg.cdr_pgsql.global.table }}"
record_dir: "{{ asterisk_recordings_dir }}"
ami_user: "{{ asterisk_ami_cdr_user }}"
ami_pass: "{{ asterisk_ami_cdr_secret }}"
when: asterisk_use_cdr | d(true) == true
- name: flush handlers
meta: flush_handlers
- name: add directories to backup plan
include_role:
name: backup
vars:
function: add
backup_items:
- "{{ asterisk_conf_dir }}"
- "{{ asterisk_tls_dir }}"
- "{{ asterisk_data_dir }}/moh"
- "{{ asterisk_data_dir }}/sounds/{{ asterisk_language }}/custom"
- "{{ asterisk_dir }}/astdb.sqlite3"
- name: enable and start asterisk
service:
name: asterisk
enabled: yes
state: started