Skip to content

Commit

Permalink
Add role prefixes to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed May 18, 2024
1 parent e6a840b commit a0f400b
Show file tree
Hide file tree
Showing 25 changed files with 369 additions and 368 deletions.
466 changes: 233 additions & 233 deletions inventory/group_vars/all/users.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion proxies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
- proxies
no_log: true
roles:
- outline
- shadowsocks
- prometheus
12 changes: 6 additions & 6 deletions roles/dynamic-dns/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
- name: Create user
user: name={{ user }}
user: name={{ dynamic_dns_user }}

- name: Copy sync script
copy:
src: sync-ip.sh
dest: "/home/{{ user }}/{{ executable_name }}"
group: "{{ user }}"
owner: "{{ user }}"
dest: "/home/{{ dynamic_dns_user }}/{{ dynamic_dns_executable_name }}"
group: "{{ dynamic_dns_user }}"
owner: "{{ dynamic_dns_user }}"
mode: "700"

- name: Remove unexpected files in home
include_tasks: tasks/remove-unexpected-files.yml
vars:
directory: "/home/{{ user }}"
directory: "/home/{{ dynamic_dns_user }}"
files:
- "{{ executable_name }}"
- "{{ dynamic_dns_executable_name }}"

- name: Render systemd service config
template:
Expand Down
4 changes: 2 additions & 2 deletions roles/dynamic-dns/templates/dynamic-dns.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Requires=dynamic-dns.timer

[Service]
Type=simple
User={{ user }}
ExecStart=/home/{{ user }}/{{ executable_name }} "{{ domain }}" "{{ record }}" "{{ godaddy_api_key }}"
User={{ dynamic_dns_user }}
ExecStart=/home/{{ dynamic_dns_user }}/{{ dynamic_dns_executable_name }} "{{ domain }}" "{{ record }}" "{{ dynamic_dns_godaddy_api_key }}"

[Install]
WantedBy=multi-user.target
2 changes: 1 addition & 1 deletion roles/dynamic-dns/templates/dynamic-dns.timer.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description="Timer for the dynamic-dns.service"

[Timer]
Unit=dynamic-dns.service
OnUnitActiveSec={{ repeat_interval }}
OnUnitActiveSec={{ dynamic_dns_repeat_interval }}

[Install]
WantedBy=timers.target
8 changes: 4 additions & 4 deletions roles/dynamic-dns/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# linux user to run scrips on behalf of
user: dynamic-dns
dynamic_dns_user: dynamic-dns

godaddy_api_key: !vault |
dynamic_dns_godaddy_api_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
66343930313362623235306462336631666536343730343933316334623762643035323636613866
3462356132376531326232656638633930636166333466640a396137656163643766373431333335
Expand All @@ -12,7 +12,7 @@ godaddy_api_key: !vault |
376661623362646566326663373531376238
# name of sync-ip script file
executable_name: sync-ip.sh
dynamic_dns_executable_name: sync-ip.sh

# frequency of dns check. in OnUnitActiveSec format (systemd)
repeat_interval: 10min
dynamic_dns_repeat_interval: 10min
38 changes: 19 additions & 19 deletions roles/frontman/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
state: present

- name: Create user
user: name={{ user }}
user: name={{ frontman_user }}

- set_fact:
static_root_local: "/tmp/{{ static_folder }}"
static_root_local: "/tmp/{{ frontman_static_folder }}"
instruction_filename: "{{ lookup('community.general.random_string', length=32, special=False) }}.html"

- set_fact:
Expand Down Expand Up @@ -56,12 +56,12 @@
index_var: loop_index
vars:
user_uuid: "{{ item.value }}"
default_server: "{{ servers[loop_index % (servers | length)] }}"
default_server: "{{ servers[1] }}"

- name: Synchronize local static root with remote host
synchronize:
src: "{{ static_root_local }}"
dest: "/home/{{ user }}"
dest: "/home/{{ frontman_user }}"
recursive: yes
archive: no
checksum: yes
Expand All @@ -83,7 +83,7 @@

- name: Get MD5 checksum of serve executable
stat:
path: "/home/{{ user }}/{{ executable_name }}"
path: "/home/{{ frontman_user }}/{{ frontman_executable_name }}"
checksum_algorithm: md5
register: file_stat

Expand All @@ -93,28 +93,28 @@
register: arch

- name: Download & extract serve executable
when: "file_stat.stat.exists == false or file_stat.stat.checksum != downloads[arch.stdout].md5"
when: "file_stat.stat.exists == false or file_stat.stat.checksum != frontman_downloads[arch.stdout].md5"
unarchive:
src: "{{ downloads[arch.stdout].url }}"
dest: "/home/{{ user }}"
src: "{{ frontman_downloads[arch.stdout].url }}"
dest: "/home/{{ frontman_user }}"
remote_src: yes
extra_opts:
- "{{ executable_name }}"
- "{{ frontman_executable_name }}"
register: download

- name: Set executable ownership, group and permissions
file:
path: "/home/{{ user }}/{{ executable_name }}"
group: "{{ user }}"
owner: "{{ user }}"
path: "/home/{{ frontman_user }}/{{ frontman_executable_name }}"
group: "{{ frontman_user }}"
owner: "{{ frontman_user }}"
mode: "700"

- name: Copy SSL key
copy:
src: "{{ ssl_key_path }}"
dest: "{{ frontman_ssl_key_path }}"
group: "{{ user }}"
owner: "{{ user }}"
group: "{{ frontman_user }}"
owner: "{{ frontman_user }}"
mode: "600"
remote_src: yes
register: ssl_private
Expand All @@ -123,19 +123,19 @@
copy:
src: "{{ ssl_cert_path }}"
dest: "{{ frontman_ssl_cert_path }}"
group: "{{ user }}"
owner: "{{ user }}"
group: "{{ frontman_user }}"
owner: "{{ frontman_user }}"
mode: "600"
remote_src: yes
register: ssl_cert

- name: Remove unexpected files in home
include_tasks: tasks/remove-unexpected-files.yml
vars:
directory: "/home/{{ user }}"
directory: "/home/{{ frontman_user }}"
files:
- "{{ static_folder }}"
- "{{ executable_name }}"
- "{{ frontman_static_folder }}"
- "{{ frontman_executable_name }}"
- "{{ frontman_ssl_cert_filename }}"
- "{{ frontman_ssl_key_filename }}"

Expand Down
6 changes: 3 additions & 3 deletions roles/frontman/templates/frontman.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Description=frontman
After=network.service

[Service]
User={{ user }}
WorkingDirectory=/home/{{ user }}
ExecStart=/home/{{ user }}/{{ executable_name }} --dir /home/{{ user }}/{{ static_folder }} --host 0.0.0.0 --port {{ frontman_port }} --ssl --cert {{ frontman_ssl_cert_filename }} --key {{ frontman_ssl_key_filename }}
User={{ frontman_user }}
WorkingDirectory=/home/{{ frontman_user }}
ExecStart=/home/{{ frontman_user }}/{{ frontman_executable_name }} --dir /home/{{ frontman_user }}/{{ frontman_static_folder }} --host 0.0.0.0 --port {{ frontman_port }} --ssl --cert {{ frontman_ssl_cert_filename }} --key {{ frontman_ssl_key_filename }}
Restart=always

[Install]
Expand Down
2 changes: 1 addition & 1 deletion roles/frontman/templates/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
const redirect = function (url) {
window.location.href = url || "{{ default_redirect }}";
window.location.href = url || "{{ frontman_default_redirect }}";
};
window.onload = function () {
Expand Down
14 changes: 7 additions & 7 deletions roles/frontman/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# linus user to run frontman as
user: frontman
frontman_user: frontman
# URL to download outline from
downloads:
frontman_downloads:
x86_64:
url: https://github.com/syntaqx/serve/releases/download/v0.5.0/serve_0.5.0_linux_x86_64.tar.gz
md5: b20d486c14c65883bb70284d3bdca010
Expand All @@ -12,13 +12,13 @@ downloads:
url: https://github.com/syntaqx/serve/releases/download/v0.5.0/serve_0.5.0_linux_armv6.tar.gz
md5: d3bad027c9ad4403de9293b200317259
# name of outline executable file
executable_name: serve
frontman_executable_name: serve
# port, configs should be served on
frontman_port: 1399
# relative path of directory where static content should be stored
static_folder: static
frontman_static_folder: static
# where redirect to if user opened index page without paramneters
default_redirect: !vault |
frontman_default_redirect: !vault |
$ANSIBLE_VAULT;1.1;AES256
34653931636161663935663035336435336238646530363730636237336266663637616338643535
3538363838646330333836393632633631636539343734650a623666633838316166333966363938
Expand All @@ -29,5 +29,5 @@ default_redirect: !vault |
frontman_ssl_cert_filename: cert.pem
frontman_ssl_key_filename: key.pem

frontman_ssl_cert_path: /home/{{ user }}/{{ frontman_ssl_cert_filename }}
frontman_ssl_key_path: /home/{{ user }}/{{ frontman_ssl_key_filename }}
frontman_ssl_cert_path: /home/{{ frontman_user }}/{{ frontman_ssl_cert_filename }}
frontman_ssl_key_path: /home/{{ frontman_user }}/{{ frontman_ssl_key_filename }}
20 changes: 10 additions & 10 deletions roles/node-exporter/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- name: Create user
user: name={{ user }}
user: name={{ node_exporter_user }}

- name: Get MD5 checksum of node-exporter executable
stat:
path: "/home/{{ user }}/{{ executable_name }}"
path: "/home/{{ node_exporter_user }}/{{ node_exporter_executable_name }}"
checksum_algorithm: md5
register: file_stat

Expand All @@ -14,30 +14,30 @@

- name: Know if the directory exists
stat:
path: "/home/{{ user }}/{{ downloads[arch.stdout].directory }}"
path: "/home/{{ node_exporter_user }}/{{ node_exporter_downloads[arch.stdout].directory }}"
register: file_stat

- name: Download & extract node-exporter
when: "file_stat.stat.exists == false"
unarchive:
src: "{{ downloads[arch.stdout].url }}"
dest: "/home/{{ user }}"
src: "{{ node_exporter_downloads[arch.stdout].url }}"
dest: "/home/{{ node_exporter_user }}"
remote_src: yes
register: download

- name: Set node-exporter ownership, group and permissions
file:
path: "/home/{{ user }}/{{ downloads[arch.stdout].directory }}/{{ executable_name }}"
group: "{{ user }}"
owner: "{{ user }}"
path: "/home/{{ node_exporter_user }}/{{ node_exporter_downloads[arch.stdout].directory }}/{{ node_exporter_executable_name }}"
group: "{{ node_exporter_user }}"
owner: "{{ node_exporter_user }}"
mode: "700"

- name: Remove unexpected files in home
include_tasks: tasks/remove-unexpected-files.yml
vars:
directory: "/home/{{ user }}"
directory: "/home/{{ node_exporter_user }}"
files:
- "{{ downloads[arch.stdout].directory }}"
- "{{ node_exporter_downloads[arch.stdout].directory }}"

- name: Render systemd service config
template:
Expand Down
6 changes: 3 additions & 3 deletions roles/node-exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Description=node_exporter

[Service]
User={{ user }}
WorkingDirectory=/home/{{ user }}
ExecStart=/home/{{ user }}/{{ downloads[arch.stdout].directory }}/{{ executable_name }} --web.listen-address=:{{ node_exporter_port }}
User={{ node_exporter_user }}
WorkingDirectory=/home/{{ node_exporter_user }}
ExecStart=/home/{{ node_exporter_user }}/{{ node_exporter_downloads[arch.stdout].directory }}/{{ node_exporter_executable_name }} --web.listen-address=:{{ node_exporter_port }}
Restart=always

[Install]
Expand Down
8 changes: 4 additions & 4 deletions roles/node-exporter/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# linus user to run prometheus as
user: node_exporter
# linus user to run node-exporter as
node_exporter_user: node_exporter

# URL to download outline from
downloads:
node_exporter_downloads:
x86_64:
url: https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
md5: 94194e281f7d67de9a06838ea1dd7d7e
Expand All @@ -16,6 +16,6 @@ downloads:
md5: b5c74984325b6b84d20a16daf24b0ee3
directory: node_exporter-1.7.0.linux-armv7
# name of node-exporter executable file
executable_name: node_exporter
node_exporter_executable_name: node_exporter
# port for node-exporter dependency
node_exporter_port: 9092
12 changes: 0 additions & 12 deletions roles/outline/templates/outline.service.j2

This file was deleted.

2 changes: 1 addition & 1 deletion roles/prometheus/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies:
- role: node-exporter
- role: outline
- role: shadowsocks
Loading

0 comments on commit a0f400b

Please sign in to comment.