This commit is contained in:
meaz 2022-05-13 15:55:45 +02:00
commit bda5cfc155
Signed by: meaz
GPG Key ID: CD7A47B2F1ED43B4
14 changed files with 290 additions and 0 deletions

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
MIT License Copyright (c) 2021 "Stichting Disroot.org"
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

5
Playbooks/hubot.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: hubot
roles:
- hubot

20
README.md Normal file
View File

@ -0,0 +1,20 @@
# Hubot - Ansible Role
This role covers deployment, configuration and software updates of Hubot. This role is released under MIT Licence and we give no warranty for this piece of software. Currently supported OS - Debian.
The role allows to install/uninstall Hubot's plugins and to connect bots to your XMPP network.
You can deploy test instance using `Vagrantfile` attached to the role.
`vagrant up`
`ansible-playbook -b Playbooks/hubot.yml`
## XMPP
Each new bot is created as a linux user with in its home path. It needs its own xmpp account.
:warning: The bots' xmpp accounts must be created for the bots to work on the server. For example, check this [Prosody documentation](https://prosody.im/doc/creating_accounts)
## CHANGELOG
- **23.04.2021** - Make it deployable

20
Vagrantfile vendored Normal file
View File

@ -0,0 +1,20 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
#config.ssh.insert_key = false
config.vm.define "hubot" do |hubot|
hubot.vm.box = "generic/debian10"
hubot.vm.provider :libvirt do |libvirt|
libvirt.memory = 256
end
hubot.vm.network "forwarded_port", guest: 80, host: 8885, host_ip: "192.168.33.18"
hubot.vm.network "forwarded_port", guest: 443, host: 4445, host_ip: "192.168.33.18"
hubot.vm.network "forwarded_port", guest: 8080, host: 8082, host_ip: "192.168.33.18"
hubot.vm.network "private_network", ip: "192.168.33.18"
end
end

37
defaults/main.yml Normal file
View File

@ -0,0 +1,37 @@
---
#HUBOT DEFAULT VARIABLES
hubot_nodejs_version: '14'
hubot_apt:
- nodejs
hubot_list:
- hubot_name: myhubot1
npm_modules:
- name: 'hubot-diagnostics'
module_enabled: 'true'
- name: 'hubot-help'
module_enabled: 'true'
- name: 'hubot-pugme'
module_enabled: 'true'
- name: 'hubot-redis-brain'
module_enabled: 'true'
- name: 'hubot-rules'
module_enabled: 'true'
- name: 'hubot-shipit'
module_enabled: 'true'
- name: 'hubot-voting'
module_enabled: 'true'
- name: 'hubot-remind-her'
module_enabled: 'true'
- name: 'hubot-open-weather-map'
module_enabled: 'true'
extra_options:
- 'HUBOT_OPEN_WEATHER_MAP_APIKEY="my_key_number"'
- 'HUBOT_OPEN_WEATHER_MAP_UNITS="metric"'
xmpp_username: 'myhubot@bot.example.org'
xmpp_password: test123test123
xmpp_room: 'myroom@example.org' # you can add multiple rooms, just separate them with a coma
# List the name of the bots to remove, separeted by a comma
hubot_delete_list: []

29
tasks/addmodules.yml Normal file
View File

@ -0,0 +1,29 @@
---
- name: '[MODULES] - Install modules'
npm:
name: '{{ item.1.name }}'
path: '/home/{{ item.0.hubot_name }}/node_modules'
state: present
with_subelements:
- "{{ hubot_list }}"
- npm_modules
become: yes
become_user: '{{ item.0.hubot_name }}'
- name: '[MODULES] - Deploy external-scripts.json config'
template:
src: hubot/external-scripts.json.j2
dest: '/home/{{ item.hubot_name }}/external-scripts.json'
owner: '{{ item.hubot_name }}'
group: '{{ item.hubot_name }}'
mode: 0644
loop: '{{ hubot_list }}'
- name: '[MODULES] - Remove extra coma in config'
replace:
path: '/home/{{ item.hubot_name }}/external-scripts.json'
regexp: ',\n]'
replace: '\n]'
loop: '{{ hubot_list }}'

19
tasks/createhubot.yml Normal file
View File

@ -0,0 +1,19 @@
---
- name: '[CREATE] - Install yo'
npm:
name: yo
global: yes
- name: '[CREATE] - Install generator-hubot'
npm:
name: generator-hubot
global: yes
- name: "[CREATE] - Generate each bot in its path when it doesn't exist"
shell: if [ ! -d "/home/{{ item.hubot_name }}/bin/" ]; then npx -c 'yo hubot --adapter=xmpp --name="{{ item.hubot_name }}" --defaults' ; fi
args:
chdir: '/home/{{ item.hubot_name }}'
loop: '{{ hubot_list }}'
become: yes
become_user: '{{ item.hubot_name }}'

24
tasks/deletehubot.yml Normal file
View File

@ -0,0 +1,24 @@
---
- name: '[DELETE] - Stop hubot service'
systemd:
name: "{{ item }}"
state: stopped
loop: '{{ hubot_delete_list }}'
- name: '[DELETE] - Delete hubot service'
file:
path: "/etc/systemd/system/{{ item }}.service"
state: absent
loop: '{{ hubot_delete_list }}'
- name: '[DELETE] - Daemon reload'
systemd:
daemon_reload: yes
- name: '[DELETE] - Delete {{ item }} user'
user:
name: "{{ item}}"
state: absent
remove: yes
loop: '{{ hubot_delete_list }}'

18
tasks/installdeps.yml Normal file
View File

@ -0,0 +1,18 @@
---
- name: '[INSTALLDEPS] - Add Nodesource apt key.'
apt_key:
url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280
id: "68576280"
state: present
- name: '[INSTALLDEPS] - Add repository for nodejs'
apt_repository:
repo: deb https://deb.nodesource.com/node_{{ hubot_nodejs_version }}.x {{ ansible_distribution_release }} main
state: present
filename: 'nodesource'
- name: '[INSTALLDEPS] - Install dependencies'
apt:
name: "{{ hubot_apt }}"
update_cache: yes

20
tasks/main.yml Normal file
View File

@ -0,0 +1,20 @@
---
- name: Add user
include: user.yml
- name: Install and configure npm and nodejs
include: installdeps.yml
- name: Generate hubot instance
include: createhubot.yml
- name: Install hubot modules
include: addmodules.yml
- name: Delete hubot
include: deletehubot.yml
when: hubot_delete_list is defined and (hubot_delete_list | length > 0)
- name: Deploy Systemd
include: systemd.yml

24
tasks/systemd.yml Normal file
View File

@ -0,0 +1,24 @@
---
- name: '[SystemD] - Deploy Systemd config'
template:
src: 'etc/systemd/system/hubot.service.j2'
dest: '/etc/systemd/system/{{ item.hubot_name }}.service'
owner: root
group: root
mode: 0644
loop: '{{ hubot_list }}'
register: config
- name: '[SystemD] - Enable systemd'
systemd:
name: "{{ item.hubot_name }}"
enabled: yes
daemon_reload: yes
loop: '{{ hubot_list }}'
- name: '[SystemD] - Restart hubot'
systemd:
name: "{{ item.hubot_name }}"
state: restarted
loop: '{{ hubot_list }}'

15
tasks/user.yml Normal file
View File

@ -0,0 +1,15 @@
---
- name: '[User] - Add group {{ item.hubot_name }}'
group:
name: '{{ item.hubot_name }}'
state: present
loop: '{{ hubot_list }}'
- name: '[User] - Add linux user {{ item.hubot_name }}'
user:
name: '{{ item.hubot_name }}'
shell: /bin/bash
group: '{{ item.hubot_name }}'
loop: '{{ hubot_list }}'

View File

@ -0,0 +1,32 @@
[Unit]
Description=Hubot is a robot
Documentation=https://hubot.github.com/docs/
Requires=network.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/{{ item.hubot_name }}
RemainAfterExit=yes
User={{ item.hubot_name }}
Restart=always
RestartSec=10
StandardOutput=syslog
SyslogIdentifier={{ item.hubot_name }}
ExecStart=/home/{{ item.hubot_name}}/bin/hubot --adapter xmpp --name {{ item.hubot_name }}
Environment="HUBOT_XMPP_USERNAME={{ item.xmpp_username }}"
Environment="HUBOT_XMPP_PASSWORD={{ item.xmpp_password }}"
Environment="HUBOT_XMPP_ROOMS={{ item.xmpp_room }}"
Environment="HUBOT_XMPP_PM_ADD_PREFIX={{ item.hubot_name }}"
{% for option in item.npm_modules %}
{% if option.extra_options is defined %}
{% for item in option.extra_options %}
{{ item }}
{% endfor %}
{% endif %}
{% endfor %}
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,8 @@
[
{% for module in item.npm_modules %}
{% if module.module_enabled == 'true' %}
"{{ module.name }}"{% if not loop.last %},
{% endif %}
{% endif %}
{% endfor %}
]