This guide bootstraps a Hubot project and manages it with systemd.
yo and generator-hubot/opt/hubot workspace- name: Deploy Hubot
hosts: hubot
become: true
vars:
hubot_user: hubot
hubot_home: /opt/hubot
tasks:
- name: Install packages on Debian family
ansible.builtin.apt:
update_cache: true
name:
- nodejs
- npm
state: present
when: ansible_os_family == "Debian"
- name: Install packages on RHEL family
ansible.builtin.dnf:
name:
- nodejs
- npm
state: present
when: ansible_os_family == "RedHat"
- name: Ensure Hubot user exists
ansible.builtin.user:
name: "{{ hubot_user }}"
system: true
create_home: true
home: "{{ hubot_home }}"
shell: /usr/sbin/nologin
- name: Ensure Hubot home exists
ansible.builtin.file:
path: "{{ hubot_home }}"
state: directory
owner: "{{ hubot_user }}"
group: "{{ hubot_user }}"
mode: "0755"
- name: Install Hubot generator tools
ansible.builtin.command: npm install -g yo generator-hubot
changed_when: false
- name: Initialize Hubot project if missing
ansible.builtin.command: >
yo hubot --owner "ops@example.com" --name "opsbot" --description "Ops bot" --adapter shell --defaults
args:
chdir: "{{ hubot_home }}"
creates: "{{ hubot_home }}/bin/hubot"
become_user: "{{ hubot_user }}"
- name: Install service environment file
ansible.builtin.copy:
dest: /etc/default/hubot
mode: "0600"
content: |
HUBOT_ADAPTER=shell
HUBOT_NAME=opsbot
- name: Install systemd unit
ansible.builtin.copy:
dest: /etc/systemd/system/hubot.service
mode: "0644"
content: |
[Unit]
Description=Hubot ChatOps Bot
After=network.target
[Service]
Type=simple
User={{ hubot_user }}
Group={{ hubot_user }}
WorkingDirectory={{ hubot_home }}
EnvironmentFile=/etc/default/hubot
ExecStart={{ hubot_home }}/bin/hubot
Restart=on-failure
[Install]
WantedBy=multi-user.target
- name: Enable and start Hubot
ansible.builtin.systemd:
name: hubot
enabled: true
state: started
daemon_reload: true
ansible-playbook -i inventory.ini hubot-install.yml