This guide installs Errbot in a Python virtual environment and manages it with systemd.
errbot service account/opt/errbot workspace/opt/errbot/venvconfig.py if missingerrbot systemd service- name: Deploy Errbot
hosts: errbot
become: true
vars:
errbot_user: errbot
errbot_home: /opt/errbot
tasks:
- name: Install dependencies on Debian family
ansible.builtin.apt:
update_cache: true
name:
- python3
- python3-pip
- python3-venv
state: present
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
ansible.builtin.dnf:
name:
- python3
- python3-pip
state: present
when: ansible_os_family == "RedHat"
- name: Ensure Errbot user exists
ansible.builtin.user:
name: "{{ errbot_user }}"
system: true
create_home: true
home: "{{ errbot_home }}"
shell: /usr/sbin/nologin
- name: Ensure Errbot home exists
ansible.builtin.file:
path: "{{ errbot_home }}"
state: directory
owner: "{{ errbot_user }}"
group: "{{ errbot_user }}"
mode: "0755"
- name: Create virtual environment
ansible.builtin.command: python3 -m venv {{ errbot_home }}/venv
args:
creates: "{{ errbot_home }}/venv/bin/activate"
- name: Install Errbot in virtual environment
ansible.builtin.pip:
name: errbot
virtualenv: "{{ errbot_home }}/venv"
- name: Initialize Errbot config if missing
ansible.builtin.command: "{{ errbot_home }}/venv/bin/errbot --init"
args:
chdir: "{{ errbot_home }}"
creates: "{{ errbot_home }}/config.py"
become_user: "{{ errbot_user }}"
- name: Install systemd unit
ansible.builtin.copy:
dest: /etc/systemd/system/errbot.service
mode: "0644"
content: |
[Unit]
Description=Errbot ChatOps Bot
After=network.target
[Service]
Type=simple
User={{ errbot_user }}
Group={{ errbot_user }}
WorkingDirectory={{ errbot_home }}
ExecStart={{ errbot_home }}/venv/bin/errbot -c {{ errbot_home }}/config.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
- name: Enable and start Errbot
ansible.builtin.systemd:
name: errbot
enabled: true
state: started
daemon_reload: true
- name: Verify Errbot service
ansible.builtin.command: systemctl is-active errbot
changed_when: false
register: errbot_status
- name: Show Errbot service status
ansible.builtin.debug:
var: errbot_status.stdout
ansible-playbook -i inventory.ini errbot-install.yml