From 8ac360837a8f2a3a806209552f231964d6288431 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 14 Sep 2019 17:00:27 -0500 Subject: [PATCH] bluetooth - iiab_installed --- roles/bluetooth/tasks/enable.yml | 73 ++++++++++++++ roles/bluetooth/tasks/install.yml | 63 ++++++++++++ roles/bluetooth/tasks/main.yml | 8 +- roles/bluetooth/tasks/rpi_install.yml | 132 -------------------------- 4 files changed, 141 insertions(+), 135 deletions(-) create mode 100644 roles/bluetooth/tasks/enable.yml create mode 100644 roles/bluetooth/tasks/install.yml delete mode 100644 roles/bluetooth/tasks/rpi_install.yml diff --git a/roles/bluetooth/tasks/enable.yml b/roles/bluetooth/tasks/enable.yml new file mode 100644 index 000000000..9696cdcb3 --- /dev/null +++ b/roles/bluetooth/tasks/enable.yml @@ -0,0 +1,73 @@ +- name: Enable & Restart 'bt-agent' service + systemd: + daemon_reload: yes + name: bluetooth + enabled: yes + state: restarted + +# enable or disable bt-agent +- name: Enable & Restart 'bt-agent' service + systemd: + daemon_reload: yes + name: bt-agent + enabled: yes + state: restarted + when: bluetooth_enabled or bluetooth_term_enabled + +- name: Disable 'bt-agent' service + systemd: + daemon_reload: yes + name: bt-agent + enabled: no + state: stopped + when: not bluetooth_enabled and not bluetooth_term_enabled + +# enable or disable bt-pan +- name: Enable & Restart 'bt-pan' service + systemd: + daemon_reload: yes + name: bt-pan + enabled: yes + state: restarted + when: bluetooth_enabled | bool + +- name: Disable 'bt-pan' service + systemd: + daemon_reload: yes + name: bt-pan + enabled: no + state: stopped + when: not bluetooth_enabled | bool + +# enable or disable bt-term +- name: Enable & Restart 'bt-term' service + systemd: + daemon_reload: yes + name: bt-term + enabled: yes + state: restarted + when: bluetooth_term_enabled | bool + +- name: Disable 'bt-term' service + systemd: + daemon_reload: yes + name: bt-term + enabled: no + state: stopped + when: not bluetooth_term_enabled | bool + +- name: Add 'bluetooth' variable values to {{ iiab_ini_file }} + ini_file: + path: "{{ iiab_ini_file }}" + section: bluetooth + option: "{{ item.option }}" + value: "{{ item.value }}" + with_items: + - option: name + value: Bluetooth + - option: description + value: '"Bluetooth services for pan and terminal."' + - option: bluetooth_enabled + value: "{{ bluetooth_enabled }}" + - option: bluetooth_term_enabled + value: "{{ bluetooth_term_enabled }}" diff --git a/roles/bluetooth/tasks/install.yml b/roles/bluetooth/tasks/install.yml new file mode 100644 index 000000000..b35817cfa --- /dev/null +++ b/roles/bluetooth/tasks/install.yml @@ -0,0 +1,63 @@ +- name: "Install bluetooth packages" + package: + name: + - bluetooth + - bluez + - bluez-tools + state: present + +- name: Create bluetooth services + template: + backup: no + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: 0644 + with_items: + - { src: 'bt-agent.service.j2', dest: '/etc/systemd/system/bt-agent.service' } + - { src: 'bt-pan.service.j2', dest: '/etc/systemd/system/bt-pan.service' } + - { src: 'bt-term.service.j2', dest: '/etc/systemd/system/bt-term.service' } + - { src: 'network.conf.j2', dest: '/etc/bluetooth/network.conf' } + +- name: Create bluetooth utility scripts + template: + backup: no + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: 0755 + with_items: + - { src: 'iiab-bt-pan-on.j2', dest: '/usr/bin/iiab-bt-pan-on' } + - { src: 'iiab-bt-pan-off.j2', dest: '/usr/bin/iiab-bt-pan-off' } + - { src: 'iiab-bt-pan-discoverable-on.j2', dest: '/usr/bin/iiab-bt-pan-discoverable-on' } + - { src: 'iiab-bt-term-on.j2', dest: '/usr/bin/iiab-bt-term-on' } + - { src: 'iiab-bt-term-off.j2', dest: '/usr/bin/iiab-bt-term-off' } + +# Bluetooth service needs /usr/lib/bluetooth/bluetoothd -C --noplugin=sap +# Copy and patch it + +- name: Copy the bluetooth service + template: + dest: /etc/systemd/system/bluetooth.service + src: /lib/systemd/system/bluetooth.service + +- name: Add -C --noplugin=sap to execStart of bluetooth service + lineinfile: + path: /etc/systemd/system/bluetooth.service + regexp: '^ExecStart=/usr/lib/bluetooth/bluetoothd' + line: 'ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=sap' + +- name: Set discoverable not to timeout + lineinfile: + path: /etc/bluetooth/main.conf + regexp: '^#DiscoverableTimeout' + line: 'DiscoverableTimeout = 0' + +- name: Add 'pan_bluetooth_installed' variable values to {{ iiab_installed }} + lineinfile: + dest: "{{ iiab_installed }}" + regexp: '^pan_bluetooth_installed' + line: 'pan_bluetooth_installed' + state: present diff --git a/roles/bluetooth/tasks/main.yml b/roles/bluetooth/tasks/main.yml index 421b9c63e..88092cbfc 100644 --- a/roles/bluetooth/tasks/main.yml +++ b/roles/bluetooth/tasks/main.yml @@ -1,4 +1,6 @@ -# This is rpi only +- include_tasks: install.yml + when: bluetooth_install and not pan_bluetooth_installed is defined + +- include_tasks: enable.yml + when: bluetooth_install or pan_bluetooth_installed is defined -- include_tasks: rpi_install.yml - when: is_rpi and bluetooth_install diff --git a/roles/bluetooth/tasks/rpi_install.yml b/roles/bluetooth/tasks/rpi_install.yml deleted file mode 100644 index 2fa925c53..000000000 --- a/roles/bluetooth/tasks/rpi_install.yml +++ /dev/null @@ -1,132 +0,0 @@ -# This is rpi only - -- name: "Install rpi bluetooth packages" - package: - name: - - bluetooth - - bluez - - bluez-tools - state: present - -- name: Create bluetooth services - template: - backup: no - src: "{{ item.src }}" - dest: "{{ item.dest }}" - owner: root - group: root - mode: 0644 - with_items: - - { src: 'bt-agent.service.j2', dest: '/etc/systemd/system/bt-agent.service' } - - { src: 'bt-pan.service.j2', dest: '/etc/systemd/system/bt-pan.service' } - - { src: 'bt-term.service.j2', dest: '/etc/systemd/system/bt-term.service' } - - { src: 'network.conf.j2', dest: '/etc/bluetooth/network.conf' } - -- name: Create bluetooth utility scripts - template: - backup: no - src: "{{ item.src }}" - dest: "{{ item.dest }}" - owner: root - group: root - mode: 0755 - with_items: - - { src: 'iiab-bt-pan-on.j2', dest: '/usr/bin/iiab-bt-pan-on' } - - { src: 'iiab-bt-pan-off.j2', dest: '/usr/bin/iiab-bt-pan-off' } - - { src: 'iiab-bt-pan-discoverable-on.j2', dest: '/usr/bin/iiab-bt-pan-discoverable-on' } - - { src: 'iiab-bt-term-on.j2', dest: '/usr/bin/iiab-bt-term-on' } - - { src: 'iiab-bt-term-off.j2', dest: '/usr/bin/iiab-bt-term-off' } - -# Bluetooth service needs /usr/lib/bluetooth/bluetoothd -C --noplugin=sap -# Copy and patch it - -- name: Copy the bluetooth service - template: - dest: /etc/systemd/system/bluetooth.service - src: /lib/systemd/system/bluetooth.service - -- name: Add -C --noplugin=sap to execStart of bluetooth service - lineinfile: - path: /etc/systemd/system/bluetooth.service - regexp: '^ExecStart=/usr/lib/bluetooth/bluetoothd' - line: 'ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=sap' - -- name: Set discoverable not to timeout - lineinfile: - path: /etc/bluetooth/main.conf - regexp: '^#DiscoverableTimeout' - line: 'DiscoverableTimeout = 0' - -- name: Enable & Restart 'bt-agent' service - systemd: - daemon_reload: yes - name: bluetooth - enabled: yes - state: restarted - -# enable or disable bt-agent -- name: Enable & Restart 'bt-agent' service - systemd: - daemon_reload: yes - name: bt-agent - enabled: yes - state: restarted - when: bluetooth_enabled or bluetooth_term_enabled - -- name: Disable 'bt-agent' service - systemd: - daemon_reload: yes - name: bt-agent - enabled: no - state: stopped - when: not bluetooth_enabled and not bluetooth_term_enabled - -# enable or disable bt-pan -- name: Enable & Restart 'bt-pan' service - systemd: - daemon_reload: yes - name: bt-pan - enabled: yes - state: restarted - when: bluetooth_enabled | bool - -- name: Disable 'bt-pan' service - systemd: - daemon_reload: yes - name: bt-pan - enabled: no - state: stopped - when: not bluetooth_enabled | bool - -# enable or disable bt-term -- name: Enable & Restart 'bt-term' service - systemd: - daemon_reload: yes - name: bt-term - enabled: yes - state: restarted - when: bluetooth_term_enabled | bool - -- name: Disable 'bt-term' service - systemd: - daemon_reload: yes - name: bt-term - enabled: no - state: stopped - when: not bluetooth_term_enabled | bool - -- name: Add 'bluetooth' variable values to {{ iiab_ini_file }} - ini_file: - path: "{{ iiab_ini_file }}" - section: bluetooth - option: "{{ item.option }}" - value: "{{ item.value }}" - with_items: - - option: name - value: Bluetooth - - option: description - value: '"Bluetooth services for pan and terminal."' - - option: bluetooth_enabled - value: "{{ bluetooth_enabled }}" - - option: bluetooth_term_enabled - value: "{{ bluetooth_term_enabled }}"