From 967953dd66c0963e40e3d184d04a3e431b9ff705 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 22 Jul 2022 01:11:31 +0200 Subject: monitoring/sachet: add task to setup smstools --- roles/monitoring/sachet/defaults/main.yml | 14 +++++++++ roles/monitoring/sachet/filter_plugins/smstools.py | 26 +++++++++++++++++ roles/monitoring/sachet/handlers/main.yml | 5 ++++ roles/monitoring/sachet/tasks/smstools.yml | 34 ++++++++++++++++++++-- 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 roles/monitoring/sachet/filter_plugins/smstools.py (limited to 'roles/monitoring/sachet') diff --git a/roles/monitoring/sachet/defaults/main.yml b/roles/monitoring/sachet/defaults/main.yml index 14a07d5f..b6924a6e 100644 --- a/roles/monitoring/sachet/defaults/main.yml +++ b/roles/monitoring/sachet/defaults/main.yml @@ -11,3 +11,17 @@ sachet_listen: 127.0.0.1:9876 # provider: 'smstools' # to: # - '+15551234578' + +# sachet_usbmodeswitch: +# "12d1:1f01": | +# TargetVendor=0x12d1 +# TargetProductList="14db,14dc" +# MessageContent="55534243000000000000000000000011060000000000000000000000000000" + +# sachet_smstools_devices: +# GSM1: +# init: 'AT^CURC=0' +# device: '/dev/ttyUSB0' +# incoming: 'yes' +# pin: '0000' +# baudrate: '115200' diff --git a/roles/monitoring/sachet/filter_plugins/smstools.py b/roles/monitoring/sachet/filter_plugins/smstools.py new file mode 100644 index 00000000..e836f8a1 --- /dev/null +++ b/roles/monitoring/sachet/filter_plugins/smstools.py @@ -0,0 +1,26 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible import errors + + +def smstools_device_options(devices): + try: + result = [] + for device, options in devices.items(): + for option, value in options.items(): + result.append({'device': device, 'option': option, 'value': value}) + return result + except Exception as e: + raise errors.AnsibleFilterError("smstools_device_options(): %s" % str(e)) + + +class FilterModule(object): + + ''' smstools filters ''' + filter_map = { + 'smstools_device_options': smstools_device_options, + } + + def filters(self): + return self.filter_map diff --git a/roles/monitoring/sachet/handlers/main.yml b/roles/monitoring/sachet/handlers/main.yml index d150d88b..51b44f98 100644 --- a/roles/monitoring/sachet/handlers/main.yml +++ b/roles/monitoring/sachet/handlers/main.yml @@ -1,4 +1,9 @@ --- +- name: restart smstools + service: + name: smstools + state: restarted + - name: restart sachet service: name: sachet diff --git a/roles/monitoring/sachet/tasks/smstools.yml b/roles/monitoring/sachet/tasks/smstools.yml index 9631a3b7..1b41fadb 100644 --- a/roles/monitoring/sachet/tasks/smstools.yml +++ b/roles/monitoring/sachet/tasks/smstools.yml @@ -1,7 +1,9 @@ --- -- name: install smstools +- name: install smstools and usb-modeswitch apt: - name: smstools + name: + - smstools + - usb-modeswitch state: present - name: add user sachet to smsd group @@ -10,4 +12,30 @@ groups: smsd append: yes -## TODO: configure smstools +- name: configure usb-modeswitch + when: sachet_usbmodeswitch is defined + loop: "{{ sachet_usbmodeswitch | dict2items }}" + loop_control: + label: "{{ item.key }}" + copy: + content: "{{ item.value }}" + dest: "/etc/usb_modeswitch.d/{{ item.key }}" + +- name: configure smstool device list + ini_file: + path: /etc/smsd.conf + section: "" + option: devices + value: "{{ sachet_smstools_devices | list | join(', ') }}" + notify: restart smstools + +- name: configure smstool devices + loop: "{{ sachet_smstools_devices | smstools_device_options }}" + loop_control: + label: "{{ item.device }} ({{ item.option }})" + ini_file: + path: /etc/smsd.conf + section: "{{ item.device }}" + option: "{{ item.option }}" + value: "{{ item.value }}" + notify: restart smstools -- cgit v1.2.3