Browse Source

Initial commit

master
Felix 6 months ago
commit
9fcb7de43c
  1. 21
      README.md
  2. 8
      defaults/main.yml
  3. 23
      tasks/folders.yml
  4. 21
      tasks/main.yml
  5. 31
      tasks/motivationbot-user.yml
  6. 102
      tasks/motivationbot.yml
  7. 11
      tasks/python.yml

21
README.md

@ -0,0 +1,21 @@
## Motivation Telegram Bot - ansible role
Deploys [Motivation Telegram Bot](https://git.ix5.org/felix/motivationbot) via
ansible.
Settings:
```
motivationbot_user: "motivationbot"
motivationbot_user_home: "/home/{{ motivationbot_user }}"
motivationbot_repo: "https://git.ix5.org/felix/motivationbot"
# Fill me in!
motivationbot_token: ""
motivationbot_chat_id: ""
```
(See `default/main.yml`)
You will also need to put a `config.py` file with the required captions inside a
subfolder called `./files/motivation-bot/` of your current playbook directory.
## License
GPLv2

8
defaults/main.yml

@ -0,0 +1,8 @@
---
motivationbot_user: "motivationbot"
motivationbot_user_home: "/home/{{ motivationbot_user }}"
motivationbot_repo: "https://git.ix5.org/felix/motivationbot"
# Fill me in!
motivationbot_token: ""
motivationbot_chat_id: ""

23
tasks/folders.yml

@ -0,0 +1,23 @@
---
- name: Chown motivationbot user directory
file:
state: directory
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: 0711
path: "{{motivationbot_user_home}}"
- name: Create motivationbot directories
file:
path: "{{motivationbot_user_home}}/{{item}}"
state: directory
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: 0770
loop:
- "bot/"
- ".config/systemd/user/"
tags:
- install
- folders

21
tasks/main.yml

@ -0,0 +1,21 @@
---
- name: motivationbot-user tasks
include_tasks: motivationbot-user.yml
tags:
- motivationbot-user
- name: folders tasks
include_tasks: folders.yml
tags:
- folders
- name: python tasks
include_tasks: python.yml
tags:
- python
- name: motivationbot tasks
include_tasks: motivationbot.yml
tags:
- motivationbot

31
tasks/motivationbot-user.yml

@ -0,0 +1,31 @@
---
- name: Check if motivationbot user exists
getent:
database: passwd
key: motivationbot
fail_key: false
register: motivationbot_user_already
ignore_errors: true
tags:
- install
- motivationbot-user
- name: Create user for motivationbot
user:
name: "motivationbot"
comment: "User for motivationbot"
home: "/home/motivationbot/"
state: present
when: motivationbot_user_already != true
ignore_errors: true
tags:
- install
- motivationbot-user
- name: Enable linger for motivationbot
shell:
cmd: loginctl enable-linger motivationbot
tags:
- install
- motivationbot-user

102
tasks/motivationbot.yml

@ -0,0 +1,102 @@
---
- name: Clone motivationbot repo with git
become: true
become_user: "{{motivationbot_user}}"
git:
repo: "{{motivationbot_repo}}"
dest: "{{motivationbot_user_home}}/bot"
version: "master"
force: true
bare: false
recursive: false
track_submodules: false
verify_commit: false
tags:
- install
- update
- motivationbot
- name: chown motivationbot folders just in case
file:
path: "{{motivationbot_user_home}}/bot"
state: directory
recurse: true
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
tags:
- install
- update
- motivationbot
- name: Install bot systemd units from git
copy:
src: "{{item.src}}"
dest: "{{item.dest}}"
remote_src: yes
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: 0640
loop:
- { src: "{{motivationbot_user_home}}/bot/motivationbot.service",
dest: "{{motivationbot_user_home}}/.config/systemd/user/motivationbot.service" }
- { src: "{{motivationbot_user_home}}/bot/motivationbot.timer",
dest: "{{motivationbot_user_home}}/.config/systemd/user/motivationbot.timer" }
tags:
- install
- update
- motivationbot
- name: Insert token into motivationbot systemd unit file
lineinfile:
path: "{{motivationbot_user_home}}/.config/systemd/user/motivationbot.service"
regexp: '^#Environment=MOTIVATION_BOT_TOKEN'
line: 'Environment=MOTIVATION_BOT_TOKEN="{{motivationbot_token}}"'
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: '0644'
tags:
- install
- update
- motivationbot
- name: Insert chat_id into motivationbot systemd unit file
lineinfile:
path: "{{motivationbot_user_home}}/.config/systemd/user/motivationbot.service"
regexp: '^#Environment=MOTIVATION_BOT_CHAT_ID'
line: 'Environment=MOTIVATION_BOT_CHAT_ID="{{motivationbot_chat_id}}"'
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: '0644'
tags:
- install
- update
- motivationbot
- name: Upload config file with captions from playbook_dir role files
copy:
src: "{{playbook_dir}}/../files/roles/motivation-bot/{{item}}"
dest: "{{motivationbot_user_home}}/bot/{{item}}"
owner: "{{motivationbot_user}}"
group: "{{motivationbot_user}}"
mode: 0600
loop:
- config.py
tags:
- install
- update
- motivationbot
- name: Enable and start motivationbot timer
become: true
become_user: "{{motivationbot_user}}"
systemd:
name: motivationbot.timer
state: restarted
scope: user
enabled: true
daemon_reload: true
tags:
- install
- update
- motivationbot

11
tasks/python.yml

@ -0,0 +1,11 @@
---
- name: Install python packages
become: true
apt: name="{{packages}}" state=present
vars:
packages:
- python3-python-telegram-bot # apt packge for pip package 'python-telegram-bot'
tags:
- install
- python
Loading…
Cancel
Save