Created
January 23, 2020 01:11
-
-
Save csiens/8cd1d8b39a817fe456e2cbcbcc72c137 to your computer and use it in GitHub Desktop.
mood music on hold updater python script and ansible playbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
sudo: true | |
tasks: | |
- block: | |
- name: ping | |
ping: | |
- name: delete old moh files | |
shell: rm /var/lib/asterisk/moh/*.wav | |
ignore_errors: yes | |
- name: copy new moh files | |
copy: | |
src: /root/mood/current_moh | |
dest: /tmp/moh_files | |
mode: 0777 | |
- name: move new moh files into place | |
shell: mv /tmp/moh_files/current_moh/*.wav /var/lib/asterisk/moh/ | |
- name: reload asterisk | |
shell: asterisk -rx "moh reload" | |
- name: reboot | |
shell: reboot | |
rescue: | |
- name: task failure | |
shell: echo "The Ansible Mood playbook failed!" | mail -s "Mood Ansible Failure!" [email protected] | |
delegate_to: localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# requires ansible, ffmpeg-normailze, and mailutils packages on ansible host | |
# imports | |
import os | |
import pathlib | |
# set up directory vars | |
new_files_dir = "/root/mood/new_moh" | |
current_moh_dir = "/root/mood/current_moh" | |
archive_dir = "/root/mood/old/old_moh" | |
# check new files directory and validate there is at least one .wav file | |
if list(pathlib.Path(new_files_dir).glob("*.wav")): | |
# rename new files | |
i = 1 | |
for wav_file in list(pathlib.Path(new_files_dir).glob("*.wav")): | |
os.system("mv " + str(wav_file).strip("'") + " " + new_files_dir + "/moh_" + str(i) + ".wav") | |
i = i + 1 | |
# normalize files with ffmpeg-normalize | |
for wav_file in list(pathlib.Path(new_files_dir).glob("*.wav")): | |
os.system("ffmpeg-normalize -f -lrt 6.0 " + str(wav_file).strip("'") + " -o " + str(wav_file).strip("'")) | |
# archive current music on hold files | |
os.system('cp -a ' + current_moh_dir + ' ' + archive_dir + '.$(date "+%Y%m%d")') | |
# clean current_moh_dir | |
os.system('rm ' + current_moh_dir + '/*.wav') | |
# move normalized files to current_moh_dir | |
os.system('mv ' + new_files_dir + '/*.wav ' + current_moh_dir) | |
# run ansible playbook to delete old moh files, copy current moh files, reload asterisk, and reboot | |
os.system('sudo /usr/bin/python2.7 /usr/local/bin/ansible-playbook /root/mood/mood_ansible_playbook.yml -u root -vv 2>&1 | tee /root/mood/mood_playbook.log') | |
else: | |
# if no valid wav files send alert email | |
os.system('echo "There are no valid files to process!" | mail -s "Mood Processor Failure!" [email protected]') | |
print("File validation failure!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment