commit
9fcb7de43c
7 changed files with 217 additions and 0 deletions
@ -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 |
@ -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: "" |
@ -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 |
@ -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 |
@ -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 |
@ -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 |
Loading…
Reference in new issue